Hi,
I am trying to use the variable 'lives' to keep track of how many times my 'Player' has touched lizard. With the code shown below however, I am unsuccessful in trying to detect the fifth time it touches the lizard so that the 'player' will be removed from the world. Is there a way to fix this problem? Thanks for the help.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class Player extends MazeCreature
{ private int lives = 5;
public Player(int size)
{
getImage().scale(size,size);
int angle = Greenfoot.getRandomNumber(4)*90;
setRotation(angle);
}
public Player()
{
this(40);
}
public void act()
{
if(canMove()) {
moveForward();
}
Actor lizard = getOneIntersectingObject(Lizard.class);
if(lizard!=null) {
lives=lives-1;
}
if(lives==0) {
Greenfoot.stop();
}
}
