Winning the Game

Add a competitive edge to your game!

Step 1

The game is fun to play, but there is no way to win the game or end the game right now: the score will just go up forever.

Make it 10 points to win the game! To do this, use an If Statement. If Statements are very common in programming. 

Go to the Control drawer, drag out an If...Then... block and snap it in the when Sprite.Touched event handler. 

Step 2

Use a Math block to write the code “If Score = 10 then…”

Step 3

When the player reaches 10 points we want the end sound to play, the Sprite to stop moving and the score to reset to zero. Add the following code to the Then section of the If Statement:

  • Call End_Sound.Start
  • Set Clock1TimerEnabled to “false” 
  • Set global Score to “0”

Hint: open the Logic drawer to find the False block.

Step 4

Test the code on your phone! You can now win the game!