This site requires JavaScript, please enable it in your browser!
Greenfoot back

hkrhässleholm's Comments

Back to hkrhässleholm's profile

Thanks danpost. I got that. More question: 1. In this game we can see that the snake always move forward (even when no key is pressed). Which method is used for that and where are the codes for those exactly?
Hi malmotri! Thanks it's clear to me now. Okay, one more thing I want to ask. In your "Board" class, inside the constructor Board, you have written a line- [ snake[0] = new Snake("head",color1);] Well, I clearly undersatand that the term "head" is snake's head and the "color1" is the corresponded color that you have chosen for the head. But my question is that (1)HOW THE GREENFOOT PROGRAM KNOWS(OR IDENTIFY THE TERM) THAT IT'S THE HEAD OF THE SNAKE? (2) IS IT ACTUALLY IMPORTED FROM GREENFOOT?
OOps!! In this game its in the Item class.
Hi danpost again! In the food class: What does these codes do actually? [Actor food=getOneIntersectingObject(SnakeHunter.class); if(food!=null){ a=Greenfoot.getRandomNumber(25); b=Greenfoot.getRandomNumber(25); setLocation(a*20+10, b*20+10);] I tried by removing line "b=Greenfoot.getRandomNumber(25);" and "setLocation(a*20+10, b*20+10);] "- but they work fine!
Hi thanks for your explanation! But something is confusing to me still now! for example, here: getX() + speedX >= 584 the value 584 has nothing to do with the speed where the value of speed is already assigned before. So why do we need to check the size of the world if its bigger than 584 or equal in term of "speedX"?
Hi Malmotri! I don't understand almost anything your "Snake" class! Could anyone please explain the codes? Specially the part I am mentioning down. public void act() { if (segment == "head") { Board board = (Board)getWorld(); for (int i = length - 1; i > 0; i--) board.snake[i].setLocation(board.snake[i - 1].getX(), board.snake[i - 1].getY()); *Why do we need to write the codes in act method? *What do "length-1" and "i--" do? *"board.snake[i].setLocation(board.snake[i - 1].getX(), board.snake[i - 1].getY());"- what does it do? *Explain the "move" method". Here : if (getX() + speedX < 0 || getX() + speedX >= 584 || getY() + speedY < 0 || getY() + speedY >= 585 -what do they do? * Actor body = getOneObjectAtOffset(speedX * 2, speedY * 2, Snake.class); -what is happening there?
Open the code tomorrow...Aseel..
Yes! open the code tomorrow coz today we have exam, let the exam over...
Hi Aseel! Good job!