2016-03-26 00:47:20 +01:00
# bop it challenges
2016-11-01 18:42:42 +01:00
a game similar to "Simon Says" with the @boardname @.
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-10-23 06:29:31 +02:00
```typescript
let action = 0;
function newAction() {}
2016-03-30 06:17:57 +02:00
input.onButtonPressed(Button.A, () => {
2016-03-26 00:47:20 +01:00
if (action == 0) {
2016-10-23 06:29:31 +02:00
game.addScore(1);
newAction();
2016-03-26 00:47:20 +01:00
}
2016-10-23 06:29:31 +02:00
})
2018-11-10 00:36:46 +01:00
input.onGesture(Gesture.LogoDown, function () {
2016-03-26 00:47:20 +01:00
if (action == 1) {
2016-10-23 06:29:31 +02:00
game.addScore(1);
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-10-23 06:29:31 +02:00
game.addScore(1);
newAction();
2016-03-26 00:47:20 +01:00
}
2016-03-31 02:15:42 +02:00
})
2016-03-30 06:17:57 +02:00
input.onButtonPressed(Button.B, () => {
2016-10-23 06:29:31 +02: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
```
2017-09-07 22:42:08 +02:00
## Challenge 1
2016-03-26 00:47:20 +01:00
2018-11-10 00:36:46 +01:00
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.randomRange(0, 3)` 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-26 00:47:20 +01:00
2016-10-23 06:29:31 +02:00
```typescript
let action = 0;
2016-07-19 12:42:42 +02:00
export function newAction() {
2018-11-10 00:36:46 +01:00
action = Math.randomRange(0, 3)
2016-03-26 00:47:20 +01:00
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) // ** *
}
}
```
2017-09-07 22:42:08 +02:00
## Challenge 2
2016-03-26 00:47:20 +01:00
2018-11-10 00:36:46 +01:00
Now let's implement `PRESS PIN 0` in the main. Create a condition in an `input.onPinPressed` event that, whet pin `P0` is pressed, will add one to the score and then calls the `newAction` function.
2016-03-26 00:47:20 +01:00
2016-10-23 06:29:31 +02:00
```typescript
let action = 0;
export function newAction() {
// ...
}
2016-03-30 06:17:57 +02:00
input.onButtonPressed(Button.B, () => {
2016-10-23 06:29:31 +02:00
basic.showNumber(game.score(), 150)
basic.pause(2000)
newAction()
})
2016-03-30 06:17:57 +02:00
input.onPinPressed(TouchPin.P0, () => {
2016-03-26 00:47:20 +01:00
if (action == 3) {
2016-10-23 06:29:31 +02:00
game.addScore(1)
newAction()
2016-03-26 00:47:20 +01:00
}
2016-10-23 06:29:31 +02:00
})
2016-03-26 00:47:20 +01:00
```
2017-09-07 22:42:08 +02:00
## Challenge 3
2016-03-26 00:47:20 +01:00
Add `POINT ME NORTH` to the list of possible commands.