my timer doesnt seem to be running... It's stuck at "hrs 00mins 00sec" whenever i run it
here's the code:
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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | import greenfoot.*; public class MyWorld extends World { // fields usually (by convention) go first GifImage gifImg = new GifImage( "Umaru.gif" ); private Actor TimeDisplay = new SimpleActor(); private int frames; private int Countdown; public float AYen; //precise public int DYen; //rounded public Yen YenDisplay = new Yen(); public int getHeight = 552 ; public int getWidth = 1200 ; // class constructors usually (by convention) go next public void gifAnimation() { for (Object obj : gifImg.getImages()) ((GreenfootImage)obj).scale(getWidth(), getHeight()); setBackground(gifImg.getCurrentImage()); } public MyWorld() { //For building the world window size super ( 1400 , 675 , 1 ); //For updating the Yen Display adjustYen( 0 ); // to initialize image prepare(); addObject(YenDisplay, 1265 , 50 ); // wherever //For updating the time display updateTimeDisplay(); addObject(TimeDisplay, 1265 , 20 ); //For triggering the minigame Cooldown(); } // methods (by convention) go last //For GIF background public void act() { gifAnimation(); } //For Yen Display stuff public int getAccumulatedYen() { return DYen; } public void adjustYen( float adjustment) { AYen += adjustment; DYen = ( int ) AYen; YenDisplay.setImage( new GreenfootImage( "Yen: " +DYen+ "¥" , 20 , Color.BLACK, new Color( 0 , 0 , 0 , 0 ))); } //For Time Display stuff private void updateTimeDisplay() { int Time = frames/ 55 ; String hours = "0" +(Time/ 3600 ); String minutes = "0" +(Time/ 60 ); String seconds = "0" +(Time% 60 ); String hrs = hours.substring(minutes.length()); String mins = minutes.substring(minutes.length()- 2 ); String secs = seconds.substring(seconds.length()- 2 ); String TimeFormat = "Time: " +hrs+ "hrs " +mins+ "mins " +secs+ "secs" ; //Preview: Time: 12345hrs 12mins 12secs TimeDisplay.setImage( new GreenfootImage(TimeFormat, 20 , Color.BLACK, new Color( 0 , 0 , 0 , 0 ))); } //For Choosing the Minigame and timing the appearance of the Minigame private void Cooldown() { int Time = frames/ 55 ; if (Countdown == 0 ) { Countdown += 2 +( 1 + Greenfoot.getRandomNumber( 5 )); //chooses a cooldown time between 3-7 minutes randomly Minigame(); } Countdown-=Time/ 60 ; } private void Minigame() { } //For placing actors into the world private void prepare() { addObject( new Umaru(), 700 , 338 ); } } |