Rock, paper, scissors
Pseudocode
- On Shake a random number will be selected between 0, 1 and 2
- If it is a 0 then display rock
- If it is a 1 then display paper
- If it is a 2 then display scissors
- If the A button is press, clear the screen for the next match
Step by Step
- Create a new code project if you haven’t done so already.
- Lets start by adding
on shake
block to your code. - Next lets create a variable called ‘hand’. This will hold a number 0, 1 or 2, where a 0 is a rock, a 1 is paper, and a 3 is scissors.
- In our
on shake
block we need to set the value of hand to our random number (0, 1, or 2) using thepick random
math block. - Next, we will add an if conditional statment that checks the value of the hand variable.
- If hand = 0 then we will display a rock using the LEDs.
- Else If hand = 1 then we will display a paper using the LEDs.
- Else is not one of the above (i.e. it is 2) then we will display scissors using the LEDs.
- Add an
on button A pressed
event, and place theclear screen
basic block in it.
When complete your code should look like this: