Skip to content

Please update your browser

Your browser version is not supported by this site. CS First may not work properly. Learn more

arrow_back It's How You Play the Game

Choose an Add-On
play_circle_filled
It's How You Play the Game
Add a winning condition to your game.
arrow_forward
play_circle_filled
Danger Sprite
Add a sprite that causes you to lose points if you or your friend touches it.
arrow_forward
play_circle_filled
Designer
Learn how to design the sprites.
arrow_forward
play_circle_filled
Blocking (Part 1 of 2)
Force the players to jump over each other.
arrow_forward
play_circle_filled
Blocking (Part 2 of 2)
Force the players to jump over each other.
arrow_forward
play_circle_filled
Make Noise
Add sound to your project.
arrow_forward
play_circle_filled
Hello Friend
Make the sprites react when they touch each other.
arrow_forward
  • 1. Variables Are Everywhere!
  • 2. Let's Move!
  • 3. One Falling Object
  • 4. Many Falling Objects
  • 5. Keeping Score
  • 6. Shared Score
  • 7. Add-Ons
  • 8. Reflection
  • 9. Wrap-up: Work Together to Win
  • 10. Wrap-up: Share Your Project
  • 11. Wrap-up: Show Your Project
arrow_backward Back Next arrow_forward
Transcript

In this video, you’ll learn how to add a winning condition to your game.

In the sprites area, click on the stage.

You’ll program the Win/Lose condition on the backdrop, rather than on one of the sprites.

Start by programming the winning condition.

First, choose a winning number of points..

This example uses 20.

You and your friend will win if the score reaches 20.

From the control menu, drag out an “if/then” block.

Remember, an “if” statement, or conditional, checks whether something is true.

Next, fill in the condition for the computer to check.

In this case, if the score is ever greater than 19, the players will have won.

From the operators menu, place a “greater than” block inside the diamond-shaped space in the “if/then” block.

On the right side of the greater than block, type the score just before the winning one.

In this example, that’s 19.

From the data menu, place the “score” variable block in the left side of the “greater than” block.

If the players have won, the backdrop will change.

From the “looks” menu, place the “switch backdrop to” block inside the “if” block.

Click on the dropdown, and select “winning backdrop.”

Next, make the game constantly check if you and your friend have won.

From the “control” menu place a “forever” loop around the “if/then” block.

The game will start checking if you and your friend won as soon as the flag is clicked.

From the “events” menu, place a “when flag clicked” block above the forever loop.

Click on the green flag to test your code.

Then, earn a winning score with your friend.

The backdrop changes!

But wait… objects are still falling from the sky.

To end the game, from the “control” menu place the “stop all” block under the “switch backdrop to” block.

Test the code by clicking the green flag again.

When you get the high score, the backdrop changes, and the objects stop dropping.

Great!

Next, follow similar steps to add a losing condition..

Make the program check if the score is equal to a negative number, and, if it is, switch the backdrop to the losing backdrop.

If you need help programming the losing condition, ask a neighbor or put up your sticky to get your Guru’s attention.

Don’t worry if your program doesn’t work the first time.

Computer scientists like you rarely get their programs to work on their first try.

They use courage and persistence to learn from their mistakes and keep trying!

Now it’s your turn: Let the players know they’ve won using “if” “greater than” “score” and “switch backdrop to” blocks.

Make the game constantly check if the players have won using a forever loop.

Stop the game when the players win using “stop all.”

Instructions
  1. Choose an Add-On, and click "watch" to learn how to build it.
  2. Once you finish one Add-On, try another one below the video!