Hi,
I want to let the game stop after a specific amount of seconds for each level. (I will implement the timed level system later on when I got this to work)
It has to end after 40 seconds. So I tried to do that this way, since I couldn't figure out another way to do this. But if I run now it's run for about 1 second and then the value of "timeLeft" becomes -1.
private int timeLeft = 40;
private int counter = 0;
public void showTimer(){
if (timeLeft <= 0) {
JOptionPane.showMessageDialog(null, "You're out of time!");
Greenfoot.stop();
}
counter++;
if (counter == 35) {
timeLeft=-1;
counter = 0;
}
GreenfootImage timer = new GreenfootImage("Time left: " + timeLeft, 26, Color.GREEN, Color.BLACK);
getWorld().getBackground().drawImage(timer, 40, 92);
}