Michael led the Advancers group this week, as Oliver was unavailable. Our plan was to work on 3 versions of Rock-Paper-Scissors:
- A one-person version where you play against the computer
- A two-person version where you and a friend play against each other on one computer
- A two-person version where you and a friend play against each other on different computers, using cloud variables (we did not get around to this)
We began by thinking about how the game works, and what we would need.
In our design, we need three sprites:
- My Player
- Opponent (either another player or the computer, depending on the version)
- Controller (a sprite that displays instructions, does the countdown, and uses broadcasts to sync the start and end
We also need several variables, the most important of which are:
- my-pick: what I pick (rock/paper/scissors)
- other-pick: what the opponent picks
- result: based on the picks, will be set to “I win”, “I lose”, or “Draw”
- number: a random number in the range 1-3 that the computer picks, which we translate into either a value for other-pick of “rock”, “paper”, or “scissors”
Here is the logic:
The controller has 5 costumes: one with instructions and four with big numbers 3,2,1,0 for the countdown.
The controller looks after the countdown, and broadcasts messages at the start and end of the countdown. Here is the controller’s code:
My sprite takes my keyboard input. When the countdown is over, it calculates who wins (result). Also, when the countdown is over, it says what I picked, waits 3 seconds, and then says who won.
Here is the start of its code – you will have to figure out the other combinations yourself!
The opponent sprite is the computer. Its sprite picks a random number 1-3 and converts it into a word rock/paper/scissors. It also says what it picked when the time is up. Here is the code:
Here is the design:
In this version, the Controller and My Sprite are the same as in the one-player version, except you might want to change My Sprite to use keys 1,2,3 for Rock, Paper, Scissors.
The Opponent Sprite code is different than before, but it is simpler: the opponent is your friend who will press 7, 8, 9 for Rock, Paper, Scissors, so you just need the code to read those key-presses:
Here are some ideas:
- You could add sound effects, celebrations, and different costumes
- You could find the rules for a more complex version and implement it: Rock-Paper-Scissors-Lizard-Spock
- You could figure out cloud variables!