i would like it so after so many seconds you win! im not sure how to do this please help!
additional info:
would like the timer to be shown in the corner of the screen and to flash up that you win
// add instance field
private int actCounter;
// in act method
runActCounter();
// add method
private void runActCounter()
{
if (++actCounter == 50 /* times seconds */) Greenfoot.stop();
}import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
/**
* Times the game so after so many minutes you win!
*
* @author Lime25Sour & Danpost
* @version (a version number or a date)
*/
public class Timer extends Actor
{
private int actCounter;
Color[] colors = { Color.GREEN, Color.BLUE };
int colorNum = 0;
int counter = 1;
/**
* Act - do whatever the Timer wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
runActCounter();
}
/**
* After 1 and a half minutes (50acts*No.ofSeconds) the method winner is called.
*/
private void runActCounter()
{
if (++actCounter == 4500 /* times seconds */) Winner();
}
/**
* Plays the winner sound, calls the ShowWin method then stops Greenfoot.
*/
public void Winner()
{
Greenfoot.playSound("Winner.wav");
ShowWin();
Greenfoot.stop();
}
/**
* Puts the words 'YOU WIN!' on the screen in green.
*/
public void ShowWin()
{
setImage(new GreenfootImage("YOU\nWIN!", 96, colors[colorNum], new Color(0, 0, 0, 0)));
}
}