Rock-Paper-Scissors with CHARGE Power Pack
Introducing Rock Paper Scissors (RPS)
Rock Paper Scissors is a simple hand game where two people shake their fists three times and then reveal either Rock ✊, Paper ✋, or Scissors ✌️ using their fingers to indicate which choice. To win, choose the choice that “beats” the other player: Rock breaks Scissors, Scissors cut Paper, Paper covers Rock. In this project, we’re going to leave the fate of our choice in the hands of the micro:bit!
What you need:
With CHARGE for micro:bit
- 2x micro:bits (V1 or V2)
- USB cable
- Chromebook, laptop, or desktop
- Access to MakeCode
- 2x CHARGE w/ wrist strap
Without CHARGE
- 2x micro:bits (V1 or V2)
- USB cable
- Chromebook, laptop, or desktop
- Access to MakeCode
- 2x Power bank or battery pack
- 2x Wrist strap, clips, tape, elastic bands
Code your RPS Game:
- Open makecode.microbit.org
- Input drawer: add “on shake”
- Variables drawer: “Make a Variable” and name it something like choice
- Variables drawer: add “set choice to 0” to “on shake”
- Math drawer: grab “pick random 0 to 10” and drop it onto the 0 in “set choice to 0”
- Logic drawer: add “if <true> then, else” block under the “set” block
- Logic drawer: grab “0 = 0” comparison block and drop it onto <true>.
- Variables drawer: grab the choice variable and drop it onto the first 0, it should now say “choice = 0”
- Basic drawer: add “show icon [heart]” and change the heart to whichever icon you think best represents a rock.
- Copy & paste the “choice = 0” block into the <false> in “else if <false> then.” Then change the 0 to 1.
- Copy & paste the “show icon” block into the else if statement. Then change the icon to whichever icon you think best represents a piece of paper.
- Paste the “show icon” block again and place it in the else statement. Then change the icon to whichever icon you think best represents a pair of scissors.
- Plug in your micro:bit, pair, download your code. Then plug in the other micro:bit, pair, download and test!
Or experiment with the finished code here:
Use the RPS Game:
Now find a partner to play Rock Paper Scissors with! Fasten the micro:bit to your arms with the CHARGE power pack or another DIY way and start playing! Simplest way is to make a fist with your micro:bit arm, bring your fist down onto your other hand to catch it.
You might notice that you have to be slower or more intense with your shakes for the micro:bit to detect it and change.
Make it better:
Unsure if the choice was the same as the last or it didn’t register your shake? Consider adding a noise once it has chosen or clearing the screen after each round. Want to make your own icons? Try using the “show LEDs” block in the Basic drawer. Want to make the game more exciting? Maybe add some flair when you win or keep track of how many times you win. Consider making the program only choose after the 3rd shake, like an actual game.