Need help......I'm having problems with the crab losing 1/20 energy everytime it moves, once the crab use up all its energy it suppose to die but code doesn't work and I don't know why. This what Ive come up with so far:
public class Crab extends Animal
{
private int wormsEaten;
private int moves;//JC.....line is an integer variable
/**
* Do whatever the crab likes to do just now.
*/
public void act()
{
if ( atWorldEdge())
{
turn(19);//JC.....if the crab sees the edge then the crab turns
}
if ( Greenfoot.getRandomNumber(100) < 10 )
{
turn(Greenfoot.getRandomNumber(90)-45);
}
move();
if ( canSee(Worm.class))
{
eat(Worm.class);//JINELLE......IF CRAB see worm then the crab eats the worm
}
moves++;//JC line increases the counter once each time the crab moves
if (moves == 20)//JC the amount of worm energy the crab can use each time they move
{
moves = 0;
if (wormsEaten > 0)
{
wormsEaten--;
}
else
{
//die?//JC if else statement used is if the number of energy units gets to zero then the crab will die
//this function represents
}
}//JC
}
}//End of Crab class