public int turtlesEaten;
World world = getWorld();
private Actor announcement;
private int delay;
public Crab()
{
turtlesEaten=0;
}
/**
* Act - do whatever the Crab wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
checkForArrowKeys(5);
eatTurtle();
endGame();
}
public void endGame()
{
if(turtlesEaten == 12)
{
world.showText("You won!",300,30);
Greenfoot.stop();
}
}
public void eatTurtle()
{
if(isTouching(Turtle.class))
{
removeTouching(Turtle.class);
turtlesEaten = turtlesEaten + 1;
announcement = new TurtleDied();
delay = 10;
getWorld().addObject(announcement,300,30);
if(delay == 0)
{
getWorld().removeObject(announcement);
}
else
{
delay--;
}
}
}
