0% found this document useful (0 votes)
122 views

Rock Paper Scissors - Microsoft MakeCode

The document provides instructions for building a rock paper scissors game using a micro:bit. It explains that shaking the micro:bit will select a random number from 1 to 3 to represent rock (2), paper (1), or scissors (3). An if/else statement displays the corresponding image on the LED screen. The code is tested in the simulator and can also be transferred to a physical micro:bit to play the game with friends.

Uploaded by

Cecilia Pereira
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
122 views

Rock Paper Scissors - Microsoft MakeCode

The document provides instructions for building a rock paper scissors game using a micro:bit. It explains that shaking the micro:bit will select a random number from 1 to 3 to represent rock (2), paper (1), or scissors (3). An if/else statement displays the corresponding image on the LED screen. The code is tested in the simulator and can also be transferred to a physical micro:bit to play the game with friends.

Uploaded by

Cecilia Pereira
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

15/05/2019 Rock Paper Scissors - Microsoft MakeCode

Rock Paper Scissors

Introduction

Use the accelerometer and the screen to build a Rock Paper Scissors game that
you can play with your friends!

Step 1
Add a on shake block to run code when you shake the micro:bit.

em agitar

Step 2
Add a hand variable and place the set hand to block in the shake event.

https://makecode.microbit.org/projects/rock-paper-scissors 1/9
15/05/2019 Rock Paper Scissors - Microsoft MakeCode

Step 3
Add a pick random block to pick a random number from 1 to 3 and store it in
the variable named hand .

em agitar

definir hand para escolher aleatório 1 para 3

In a later step, each of the possible numbers ( 1 , 2 , or 3 ) is matched to its own


picture. The picture is shown on the LEDs when its matching number is picked.

Step 4
Place an if block under the pick random and check whether hand is equal to
1 . Add a show leds block that shows a picture of a piece of paper. The number 1
will mean paper.

https://makecode.microbit.org/projects/rock-paper-scissors 2/9
15/05/2019 Rock Paper Scissors - Microsoft MakeCode

em agitar

definir hand para escolher aleatório 1 para 3

se hand = 1 então

mostrar leds

Step 5
Click on the SHAKE button in the simulator. If you try enough times, you should see a
picture of paper on the screen.

https://makecode.microbit.org/projects/rock-paper-scissors 3/9
15/05/2019 Rock Paper Scissors - Microsoft MakeCode

Step 6
Click the (+) button to add an else section.

https://makecode.microbit.org/projects/rock-paper-scissors 4/9
15/05/2019 Rock Paper Scissors - Microsoft MakeCode

em agitar

definir hand para escolher aleatório 1 para 3

se hand = 1 então

mostrar leds

senão

Step 7
Add a show leds block inside the else . Make a picture of a scissors in the LEDs.

https://makecode.microbit.org/projects/rock-paper-scissors 5/9
15/05/2019 Rock Paper Scissors - Microsoft MakeCode

em agitar

definir hand para escolher aleatório 1 para 3

se hand = 1 então

mostrar leds

senão

mostrar leds

Step 8
Click the + button again to add an else if section. Now, add a conditional block
for hand = 2 to the condition in else if . Since hand can only be 1 , 2 , or 3 ,
your code is covering all possible cases!

https://makecode.microbit.org/projects/rock-paper-scissors 6/9
15/05/2019 Rock Paper Scissors - Microsoft MakeCode

Step 9
Get one more show leds block and put it in the else if . Make a picture of a rock
in the LEDs.

https://makecode.microbit.org/projects/rock-paper-scissors 7/9
15/05/2019 Rock Paper Scissors - Microsoft MakeCode

em agitar

definir hand para escolher aleatório 1 para 3

se hand = 1 então

mostrar leds

a não ser que hand = 2 então

mostrar leds

senão

mostrar leds

Step 10

https://makecode.microbit.org/projects/rock-paper-scissors 8/9
15/05/2019 Rock Paper Scissors - Microsoft MakeCode

Click on the SHAKE button in the simulator and check to see that each image is
showing up.

Step 11
If you have a micro:bit, click on Transferir and follow the instructions to get the code
onto your micro:bit. Your game is ready! Gather your friends and play Rock Paper
Scissors!

https://makecode.microbit.org/projects/rock-paper-scissors 9/9

You might also like