move lessons out of web site
will move select lessons back to "educators" section
This commit is contained in:
32
olddocs/lessons/game-counter/activity.md
Normal file
32
olddocs/lessons/game-counter/activity.md
Normal file
@ -0,0 +1,32 @@
|
||||
# game counter activity
|
||||
|
||||
Have you ever tried to create a game counter? The concept is fairly simply: increase the game `score` with `on button pressed` .
|
||||
|
||||
Let's start by adding `on button (A) pressed` will run each time the user presses A. Let's add a line of code that increments `score` by `1`.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
game.addScore(1);
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
Let's add a `add points to score` block to keep track of the current count. Since the count will change with the `add points to score` blocks, add a game block `score` to display the count on screen.
|
||||
|
||||
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
game.addScore(1);
|
||||
basic.showNumber(game.score())
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
|
||||
### ~avatar boothing
|
||||
|
||||
Excellent, you're ready to continue with the [challenges](/lessons/game-counter/challenges)!
|
||||
|
||||
### ~
|
||||
|
37
olddocs/lessons/game-counter/challenges.md
Normal file
37
olddocs/lessons/game-counter/challenges.md
Normal file
@ -0,0 +1,37 @@
|
||||
# game counter challenges
|
||||
|
||||
Coding challenges for the game counter.
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the following [activity](/lessons/game-counter/activity) . Your code should look like this:
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
game.addScore(1);
|
||||
basic.showNumber(game.score())
|
||||
});
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
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())
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
### Challenge 3
|
||||
|
||||
Now let's try to reset the counter when the micro:bit is shaken. You will need to register an event handler with `on shake`.
|
||||
|
Reference in New Issue
Block a user