public void act()
{
//to move the snake
move(9);
if(Greenfoot.isKeyDown("up")){
setRotation(-90);
}
if(Greenfoot.isKeyDown("down")){
setRotation(90);
}
if(Greenfoot.isKeyDown("left")){
setRotation(180);
}
if(Greenfoot.isKeyDown("right")){
setRotation(0);
}
//to eat the burger
if(isTouching(burger.class)){
started();
removeTouching(burger.class);
((background) getWorld()).counter();
getWorld().addObject(new burger(), Greenfoot.getRandomNumber(595), Greenfoot.getRandomNumber(395));
}
//stop the game if snake touches the edges
if (getY()== 0) {
((background)getWorld()).gameOver();
}
if (getX()==0) {
((background)getWorld()).gameOver();
}
if (getY()>398) {
((background)getWorld()).gameOver();
}
if(getX()>598){
((background)getWorld()).gameOver();
}
}
public void started(){
{
Greenfoot.playSound("chord.wav");
}
this is the code to move the snake as well as eat the object when it touches it, i hav read other post regarding growing the snake using arrays like snakeBody.length, i needed a simpler one if possible without the use of arrays!!