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


1 2 3 4 5 6 7 8 9 | // add instance field private int actCounter; // in act method runActCounter(); // add method private void runActCounter() { if (++actCounter == 50 /* times seconds */ ) Greenfoot.stop(); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | 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 ))); } } |