This site requires JavaScript, please enable it in your browser!
Greenfoot back
Hpage17
Hpage17 wrote ...

2015/6/29

Help with my countdown timer

Hpage17 Hpage17

2015/6/29

#
I am trying to make a countdown timer for my game, and I am not sure what to do. Here is my code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
private int time;
   public Level1()
   {   
       super(650, 450, 1);
       time = 6000;
       point = 0;
       prepare();
   }
   private void act()
   {
       time--;
       showTime();
   }
   private void showTime()
   {
       showText("Time: " + time/100, 50, 50);
   }
Game/maniac Game/maniac

2015/6/29

#
Have you got a method called showText()?
Super_Hippo Super_Hippo

2015/6/29

#
'showText' is a World method. I don't see mistakes there. What is happening and what do you want to happen?
Game/maniac Game/maniac

2015/6/29

#
Wow, is that a new function, I've never seen it before.
danpost danpost

2015/6/29

#
Game/maniac wrote...
Wow, is that a new function, I've never seen it before.
It was added to the World class with greenfoot version release 2.4.0.
Hpage17 Hpage17

2015/6/30

#
Here is what it says: Cannot find symbol -variable point. I want a countdown timer to be displayed on screen showing the player how much time they have left to complete a task.
Hpage17 Hpage17

2015/6/30

#
And when time is up, it turns to a gameover screen. Btw, this is in a world class
danpost danpost

2015/6/30

#
All the code you gave above except for lines 6 and 7 should be sufficient for your timer to execute and display. The variable 'point' on line 6 is not part of the timer and I cannot say why you have that line in your code. However, it should either be removed or it should be declared at the top of the class where 'time' is declared (around line 1).
danpost danpost

2015/6/30

#
Hpage17 wrote...
And when time is up, it turns to a gameover screen. Btw, this is in a world class
After lines 11 and 12 (in the act method, after decrementing and showing the new timer value), add a conditional block of code where the condition is if the time remaining is zero and where the block of code performs the game over routine (showing a game over message and stopping the scenario, for example).
Hpage17 Hpage17

2015/6/30

#
Ok, removing line 6 in the world class and changing the private void act to public void act made it show up on screen. But could you show me the code I should put in class act method?
danpost danpost

2015/6/30

#
Hpage17 wrote...
Ok, removing line 6 in the world class and changing the private void act to public void act made it show up on screen. But could you show me the code I should put in class act method?
I gave you sufficient information as to what to put in there (and where).
Hpage17 Hpage17

2015/6/30

#
Ok, I got it Thanks for the help.
You need to login to post a reply.