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

2012/11/24

NEED HELP-

1
2
myheartwillgoon myheartwillgoon

2012/11/24

#
Hi in my snake game my snake can increse it's segments unlimited by eating food. But I want my lenght of snake with max ten segments. My requirement is like this: "Max length of the snake shall be 10 segments." Please if anyone can help me... THE LINK OF MY SCENERIO IS http://www.greenfoot.org/scenarios/6742
-nic- -nic-

2012/11/24

#
ill look for you
myheartwillgoon myheartwillgoon

2012/11/24

#
thanks..i will be waiting
-nic- -nic-

2012/11/24

#
when you come to eating the food just test to see if length is bigger than ten then dont add a circle
myheartwillgoon myheartwillgoon

2012/11/24

#
the lenghth is bigger than ten, i saw that
myheartwillgoon myheartwillgoon

2012/11/24

#
what I meant is I want to increase the length of the snake by eating food but not more that 10 segments.
-nic- -nic-

2012/11/24

#
how much food does it take to make it to 10 segments?
myheartwillgoon myheartwillgoon

2012/11/24

#
8 foods. because the snake already has 2 segments from the beginning. By eating 8 foods, it then make 8+2= 10 segments.
-nic- -nic-

2012/11/24

#
then make it if the length is bigger than 8 then dont add segmant
myheartwillgoon myheartwillgoon

2012/11/24

#
How? and where ? can u tell me pls
danpost danpost

2012/11/24

#
In your 'eat' method, just put a condition on adding a segment by saying "if the length is less than 10, add a segment and increment length."
if (length<10)
    snakeEarth.addObject(snakeEarth.snake[length], getX(), getY());
    length++;
}
-nic- -nic-

2012/11/24

#
you beat me to it danpost :D
myheartwillgoon myheartwillgoon

2012/11/24

#
Hi at first I appreciate the time and patient of both of you danpost& -nic-. But the problem is that I am not sure that you clearly understand what I want to do actually. I dont want the snake's body more than 10 segments. I can make it more clear if I just copy paste of my school Snake project instruction below: (Number 7 will be focused) Here are the requirements for the game. Okay, Now I turn back to the danpost. If I compile those codes then it says that Can't find the symbol variable "SnakeEarth" If so, then please tell me what can I do now.
danpost danpost

2012/11/24

#
What does your eat method in the Snake class look like, now? Please post it here.
myheartwillgoon myheartwillgoon

2012/11/24

#
My eat method: private void eat() { Actor food=getOneObjectAtOffset(0,0,Food.class); if (food!=null){ SnakeEarth snakeEarth=(SnakeEarth)getWorld(); snakeEarth.addArray(); snakeEarth.removeObject(food); snakeEarth.snake = new Snake(); snakeEarth.addObject(snakeEarth.snake, getX(), getY()); length++; }
There are more replies on the next page.
1
2