Hardware Reference
In-Depth Information
2. If there are less than zero seconds left, set the gameOver flag to True and post
a message to the chat:
if secondsLeft < 0:
gameOver = True
mc.postToChat("Out of time...")
3. Run the program. After 30 seconds (as this is level 1), the program should end
and the message “Out of time. . .” should appear (see Figure 9-12).
FIGURE.9-12 Let your players know when they run out of time.
DIGGING INTO THE CODE
The number of seconds that are left for the level is calculated using the following
code:
secondsLeft = TIMEOUTS[level] - (time.time() - start)
The variable secondsLeft is set by taking the number of seconds that are
allowed for this level from the TIMEOUTS constant:
TIMEOUTS[level]
Then you subtract how many seconds the player has been playing the level. This
is the time now, minus the time when the level started:
(time.time() - start)
 
Search WWH ::




Custom Search