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

2012/4/26

Counter help, please

lolokay lolokay

2012/4/26

#
Every 40th cycle, the time counter variable decrements by 1, the clock is updated with the new time, the counter variable is reset otherwise the counter increases by 1 I am not entirely sure how to write my code to make this happen, so far I have private int timeCounter; // counts the time backward from 15. Represents the amt of time player has to clear the board private int counter; // counts the iterations of the act method. public void timer(){ int counter = 0 int i = 0; int timeCounter = 15; while (i == 40) timeCounter--; updateClock(timeCounter); timeCounter = 0; } Can someone please help?
ttamasu ttamasu

2012/4/26

#
for one thing you should be incrementing the counter in the act() method which represents one cycle. What you are doing is making a while loop which which would be done before I could even type one character., so I redid your snippet so that when counter = 0; its done. I assume that updateClock will update your clock image and timer is called from the act () method. private static final TIME_LIMIT = 15; private int timeCounter = 0; private int counter = TIME_LIMIT; private void timer() if (counter > 0) if (timeCounter++ >= 40) { timeCounter = 0; updateClock(counter--); } }
You need to login to post a reply.