Sie sind auf Seite 1von 7

4/8/2019 Actividad Piedra papel tijeras | micro:bit

Actividad Piedra papel tijeras


¡Haz un divertido juego de Piedra Papel Tijera en esta actividad!

Edades 8+

30 minutos

MakeCode Editor

Introducción
This project teaches you how to create a game of rock paper scissors using the "random" block
and the LEDs.

Teacher Guide
Learning Objectives
The students can:

Create a randomly generated variable

Use a IF...THEN...ELSE statements

Use the score system

Standards Alignment (United Kingdom: CAS)


Designs simple algorithms using loops, and selection i.e. if statements. (AL)

Declares and assigns variables. (AB)

Uses a variable and relational operators within a loop to govern termination. (AL) (GE)

Uses logical reasoning to predict outcomes. (AL)

Detects and corrects errors i.e. debugging, in algorithms. (AL)

Creates programs that implement algorithms to achieve given goals. (AL)

https://microbit.org/es/2017-03-07-rock-paper-scissors/ 1/7
4/8/2019 Actividad Piedra papel tijeras | micro:bit

Understands that programming bridges the gap between algorithmic solutions and
computers.(AB)

Uses nested selection statements. (AL)

Activity
Step One
We want the micro:bit to choose rock, paper, or scissors when you shake it. Place a on shake
block so when you shake the micro:bit, it will run part of a program.

on shake

Step Two
Add a weapon variable to store a random number computed with pick random.

When you shake the micro:bit, it should pick a random number from 1 to 3 and store it in the
variable weapon. (This variable is named weapon because rock, paper, and scissors are the
weapons you use to battle your friends!)

let weapon = 0
input.onGesture(Gesture.Shake, function () {
weapon = Math.randomRange(1, 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 number is picked.

Step Three
Place an if block under the pick random and check whether weapon is equal to 1.

https://microbit.org/es/2017-03-07-rock-paper-scissors/ 2/7
4/8/2019 Actividad Piedra papel tijeras | micro:bit

let weapon = 0
input.onGesture(Gesture.Shake, function () {
weapon = Math.randomRange(1, 3)
if (weapon == 1) {

}
})

Step Four
In the if block, place a show leds block that shows a picture of a piece of paper.

let weapon = 0
input.onGesture(Gesture.Shake, function () {
weapon = Math.randomRange(1, 3)
if (weapon == 1) {
basic.showLeds(`
# # # # #
# . . . #
# . . . #
# . . . #
# # # # #
`)
}
})

Step Five
Click '+' to add an 'else' and 'else if' section, then add a condition to check whether weapon is
equal to 1.

https://microbit.org/es/2017-03-07-rock-paper-scissors/ 3/7
4/8/2019 Actividad Piedra papel tijeras | micro:bit

let weapon = 0
input.onGesture(Gesture.Shake, function () {
weapon = Math.randomRange(1, 3)
if (weapon == 1) {
basic.showLeds(`
# # # # #
# . . . #
# . . . #
# . . . #
# # # # #
`)
} else if (weapon == 2) {

} else {

}
})

Paso 6
Place a show leds block under the else if and draw a rock image on the screen.

https://microbit.org/es/2017-03-07-rock-paper-scissors/ 4/7
4/8/2019 Actividad Piedra papel tijeras | micro:bit

let weapon = 0
input.onGesture(Gesture.Shake, function () {
weapon = Math.randomRange(1, 3)
if (weapon == 1) {
basic.showLeds(`
# # # # #
# . . . #
# . . . #
# . . . #
# # # # #
`)
} else if (weapon == 2) {
basic.showLeds(`
. . . . .
. # # # .
. # # # .
. # # # .
. . . . .
`)
} else {

}
})

Paso siete
Add a show leds block with a picture of scissors to the else part.

You don’t need to check if weapon is 2 because 2 is the only number left out of 0, 1, and 2.
That’s why you can use an else instead of an else if (click the '+' button to add extra else / else
if statements to your condition).

https://microbit.org/es/2017-03-07-rock-paper-scissors/ 5/7
4/8/2019 Actividad Piedra papel tijeras | micro:bit

let weapon = 0
input.onGesture(Gesture.Shake, function () {
weapon = Math.randomRange(1, 3)
if (weapon == 1) {
basic.showLeds(`
# # # # #
# . . . #
# . . . #
# . . . #
# # # # #
`)
} else if (weapon == 2) {
basic.showLeds(`
. . . . .
. # # # .
. # # # .
. # # # .
. . . . .
`)
} else {
basic.showLeds(`
# # . . #
# # . # .
. . # . .
# # . # .
# # . . #
`)
}
})

Step Eight
Your game is ready! Gather your friends and play Rock Paper Scissors!

Challenge
Try to add the following functionality:

Display animations for the different options

Change it for Rock Paper Scissors Spock Lizard

Learn More
The 'Magic Button' activity introduces inbuilt sensors, teaching you how to measure magnetism.

https://microbit.org/es/2017-03-07-rock-paper-scissors/ 6/7
4/8/2019 Actividad Piedra papel tijeras | micro:bit

https://microbit.org/es/2017-03-07-rock-paper-scissors/ 7/7

Das könnte Ihnen auch gefallen