pxt-calliope/olddocs/lessons/bop-it/activity.md

84 lines
1.9 KiB
Markdown
Raw Normal View History

2016-03-26 00:47:20 +01:00
# bop it challenges
2016-06-02 06:19:16 +02:00
a game similar to "Simon Says" with the BBC micro:bit.
2016-03-26 00:47:20 +01:00
## Before we get started
2016-03-31 02:15:42 +02:00
Complete the following guided tutorial. Your code should look like this:
2016-03-26 00:47:20 +01:00
2016-03-31 02:15:42 +02:00
```blocks
2016-03-26 00:47:20 +01:00
newAction() // ***
input.onButtonPressed(Button.A, () => {
2016-03-26 00:47:20 +01:00
if (action == 0) {
game.addScore(1) // ***
newAction() // ***
}
}) // ***
input.onLogoDown(() => {
if (action == 1) {
game.addScore(1) // ***
2016-03-31 02:15:42 +02:00
newAction()
2016-03-26 00:47:20 +01:00
}
2016-03-31 02:15:42 +02:00
})
2016-03-26 00:47:20 +01:00
input.onGesture(Gesture.Shake, () => {
if (action == 2) {
2016-03-31 02:15:42 +02:00
game.addScore(1)
newAction()
2016-03-26 00:47:20 +01:00
}
2016-03-31 02:15:42 +02:00
})
input.onButtonPressed(Button.B, () => {
2016-03-26 00:47:20 +01:00
basic.showNumber(game.score(), 150) // ***
basic.pause(2000) // ***
newAction() // ***
2016-03-31 02:15:42 +02:00
})
2016-03-26 00:47:20 +01:00
```
### Challenge 1
Now let's add some more types of instructions for the player to follow. Let's add `PRESS PIN 0`. Change the global variable `action` to `math->random(4)` so that we can add a new **IF** statement that checks if `action=3`. If it does, display instructions to press pin 0.
2016-03-31 02:15:42 +02:00
```blocks
2016-03-26 00:47:20 +01:00
/**
* {highlight}
*/
export function newAction_() {
action = Math.random(4) // ***
if (action == 0) {
basic.showString("PUSH A", 150) // ***
}
if (action == 1) {
basic.showString("LOGO DOWN", 150) // ***
}
if (action == 2) {
basic.showString("SHAKE", 150) // ***
}
if (action == 3) {
basic.showString("PRESS PIN 0", 150) // ***
}
}
```
### Challenge 2
Now let's implement `PRESS PIN 0` in the main. Create a condition of `input->on pin pressed("P0")` that will add one to the score and calls the method `new action`.
```
// **. . .**
input.onButtonPressed(Button.B, () => {
2016-03-26 00:47:20 +01:00
basic.showNumber(game.score(), 150) // ***
basic.pause(2000) // ***
newAction() // ***
}) // ***
input.onPinPressed(TouchPin.P0, () => {
2016-03-26 00:47:20 +01:00
if (action == 3) {
game.addScore(1) // ***
newAction() // ***
}
}) // ***
```
### Challenge 3
Add `POINT ME NORTH` to the list of possible commands.