2016-03-25 16:47:20 -07:00
|
|
|
# game counter challenges
|
|
|
|
|
|
|
|
Coding challenges for the game counter.
|
|
|
|
|
|
|
|
## Before we get started
|
|
|
|
|
2016-04-13 08:27:45 -07:00
|
|
|
Complete the following [activity](/lessons/game-counter/activity) . Your code should look like this:
|
2016-03-25 16:47:20 -07:00
|
|
|
|
|
|
|
```blocks
|
|
|
|
input.onButtonPressed(Button.A, () => {
|
|
|
|
game.addScore(1);
|
|
|
|
basic.showNumber(game.score())
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2017-09-07 13:42:08 -07:00
|
|
|
## Challenge 1
|
2016-03-25 16:47:20 -07:00
|
|
|
|
|
|
|
Let's add the code to `score` when `B` is pressed. Add an event handler with `on button (B) pressed` then add the code to `score`.
|
|
|
|
|
|
|
|
|
|
|
|
```blocks
|
|
|
|
input.onButtonPressed(Button.A, () => {
|
|
|
|
game.addScore(1);
|
|
|
|
basic.showNumber(game.score())
|
|
|
|
});
|
|
|
|
|
|
|
|
input.onButtonPressed(Button.B, () => {
|
|
|
|
game.addScore(-1);
|
|
|
|
basic.showNumber(game.score())
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
|
2017-09-07 13:42:08 -07:00
|
|
|
## Challenge 3
|
2016-03-25 16:47:20 -07:00
|
|
|
|
2016-11-01 17:44:37 -07:00
|
|
|
Now let's try to reset the counter when the @boardname@ is shaken. You will need to register an event handler with `on shake`.
|
2016-03-25 16:47:20 -07:00
|
|
|
|