Hardware Reference
In-Depth Information
Setting the.Level as.Complete
and.Calculating Points
When the player completes a level, the program needs to calculate how many points he
has scored and put the game on to the next level. he player scores points if he com-
pletes the level. He receives one point for every diamond he has collected, multiplied
by the number of seconds left on the clock.
To do that, you need to include the following code. The new code needs to be indented
under the
game
loop, but it has to come after the
level
loop has finished:
1.
Indented under the
game
loop, but after the
level
loop, check to see if the level
was completed:
#game loop
while not gameOver:
[code]
#level loop
while not gameOver and not levelComplete:
[code]
if levelComplete:
2.
If the level was completed, calculate the points scored and add them to the
points
variable, before posting the results to the chat:
points = points + (DIAMONDS[level] * int(secondsLeft))
mc.postToChat("Level Complete - Points = " +
↩
str(points))
3.
Set the game to the next level by adding 1 to the
level
variable:
level = level + 1
4.
If this is the last level, set the
gameOver
flag to
True
and post a message of
congratulations to the chat:
if level == LEVELS:
gameOver = True
mc.postToChat("Congratulations - All levels
↩
complete")
he
LEVELS
constant holds the total number of levels in the game.
5.
Run the program.