This is my code so far.
In the lives class
In the Hero class:
The problem I am having is if I press the reset button the number of lives does not go back to three (which is what I want). Instead it stays at the number that i had before. Does anyone know how to fix this?
public class Lives extends Actor
{
/**
* Act - do whatever the Lives wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
// Static variable here from the Crab class.
GreenfootImage textImage = new GreenfootImage("Lives - " + Hero.numLives, 24, new Color(50, 255, 100), new Color(0, 0, 0, 0));
GreenfootImage image = new GreenfootImage(textImage.getWidth()+12, 36);
image.setColor(new Color(196, 0, 0));
image.fill();
image.setColor(new Color(100, 0, 196));
image.fillRect(3, 3, image.getWidth()-6, 30);
image.drawImage(textImage, 6, 6);
setImage(image);
}
}/**
*
*/
public void lookForEnemy()
{
if (canSee(Enemy.class))
{
// Take away a life and see if you're out
numLives--;
if (numLives == 0)
{
// Bring up the "Lose" world
Greenfoot.setWorld(new Loser());
Greenfoot.stop();
}
else
{
// Respawn in another spot
setLocation(Greenfoot.getRandomNumber(getWorld().getWidth()), Greenfoot.getRandomNumber(getWorld().getHeight()));
}
}
}

