So I successfully created a timer for my game, and made it so that if the timer goes to 0, it goes to a "You Lose" page.
My problem is how to get the program to recognize when the player wins, and go to the "You Win" page.
The objective of my game is to go through a maze to get to a door. How do I make it so that if the player gets to the door before the time goes up, it will switch to the "You Win" page?
Thanks!
Here is the code i have for the timer:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
public class Timer extends Actor
{
/**
* Act - do whatever the Timer wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
private int time = 20;
private int count = 65;
public void act()
{
// Add your action code here.
if(time == 0)
{
Greenfoot.setWorld(new YouLose());
return;
}
if(counter())
{
time--;
count = 65;
}
display();
}
private boolean counter()
{
if(count > 0)
{
count--;
}
return count == 0;
}
private void display()
{
setImage(new GreenfootImage("Time Left: " + time, 30, Color.BLACK, Color.WHITE));
}
public void setTime()
{
time = 20;
}
public boolean isTimeUp()
{
return time == 0;
}
}
