Turn your micro:bit into a Rock Paper Scissors game that you can play with your friends!
1. First we need to make a variable to keep track of whether we have a Rock, Paper or Scissors in our hand. A variable is a container for storing values. Click on the Variables category in the Toolbox. Click on the Make a Variable button. Give your new variable the name "hand" and click Ok.
2. Click on the Variables category in the Toolbox again. You'll notice that there are some new blocks that have appeared. Drag a set hand block into the 🔴 on shake block. We'll start our Rock Paper Scissors game when we 👋 shake our micro:bit.
3. Click one the Math category in the Toolbox. Drag a pick random block and drop it into the set hand block replacing the number 0. Now when we shake our micro:bit, the variable hand will contain a random number between 1 and 3.
4. Click on the 🔀 Logic category in the Toolbox. Drag the 🔀 if true then else block out to the workspace and drop it into the 🔴on shake block under the set hand block.
5. From the 🔀Logic category, drag a 🔀0 = 0 comparison block and drop it into the if true then else block replacing true.
6. Click on the Variables category in the Toolbox. Drag a hand block out and drop it into the 0 = 0 comparison block replacing the first 0. Click on the second 0 in the comparison block and change to 1.
7. Click on the Basic category in the Toolbox. Drag a show icon block out and drop it under 🔀if hand = 1 then. In the show icon block, click on the Heart icon and instead select the small square icon to represent a Rock.
8. At the bottom of the 🔀 if then else block, click on the plus '+' sign. This will expand the code to include an 🔀 else if clause.
9. From the 🔀 Logic category, drag a 🔀 0 = 0 comparison block and drop it into the open space next to the else if clause.
10. From the Variables category, drag a hand block and drop it into the 🔀 0 = 0 comparison block replacing the first 0. Click on the second 0 in the comparison block and change to 2.
11. From the Basic category, drag a show icon block out and drop it under 🔀 else if hand = 2 then. In the show icon block, click on the Heart icon and instead select the large square icon to represent 📄 Paper.
12. Now let's deal with the last condition - if our hand variable isn't holding a 1 (Rock) or a 2 (Paper), then it must be 3 (✂️ Scissors)! From the Basic category drag another show icon block out and drop it into the last opening under the 🔀 else. In the show icon block, click on the Heart icon and select the Scissors icon.
13. Let's test your code! Press the white SHAKE button on the micro:bit on-screen simulator, or move your cursor quickly back and forth over the simulator. Do you see the icons for rock, paper and scissors randomly appear? ⭐ Great job! ⭐