|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| How do I set up a timer in a game? | |||||||||||||||||||||||||||||||||||||
|
Use resett and timer. Resett stands for reset timer. It resets the built-in timer to 0. Timer reports elapsed time in tenths of seconds. So to announce the time in seconds, we divide timer by 10.
Notes: Int outputs the integer portion of the elapsed time (to avoid rapidly-changing decimals when we divide). You may display the time in a textbox or just keep track "behind the scenes" and make an announcement about the time when the game ends. Or you may do both, as in the game above. If you display the time in a textbox, you may round to the nearest second (as demonstrated above), or omit the primitive int if you wish to display tenths of seconds. If the game runs for quite a long time, as in the 100-ball project below, you might wish to display minutes instead of seconds and display your running score as well. In this project, the final announcement displays elapsed minutes and seconds. Name your textboxes score and minutes and modify your procedures:
Note: These projects also demonstrate two methods for keeping score. See How do I keep score in a game? for more information. |
|||||||||||||||||||||||||||||||||||||
|