Migrate docs from the other repo

This commit is contained in:
Michal Moskal
2016-03-25 16:47:20 -07:00
parent 38d2cf06d2
commit a08eb53f92
895 changed files with 36888 additions and 0 deletions

View File

@ -0,0 +1,87 @@
# spinner activity
create an arrow that randomly points to a player. #docs
To create a new script, go to the [Create Code](/microbit/create-code) page and tap *New Project* under **Touch Develop**.
Let's begin by adding an `input->on shake` condition to know when the BBC micro:bit is shaken.
```
input.onGesture(Gesture.Shake, () => {
})
```
Now let's randomly generate a number from 0 to 3 so that we can randomly display an arrow in a given direction.
```
input.onGesture(Gesture.Shake, () => {
let randomArrow = Math.random(4)
})
```
Now let's handle each of the cases by displaying the appropriate arrow. (Let's display an up arrow if `random arrow` is 0.
```
input.onGesture(Gesture.Shake, () => {
let randomArrow1 = Math.random(4)
if (randomArrow1 == 0) {
basic.showLeds(`
. . # . .
. # # # .
# # # # #
. . # . .
. . # . .
`, 400)
}
})
```
Now let's handle the rest of the cases for `random arrow`.
```
input.onGesture(Gesture.Shake, () => {
let randomArrow2 = Math.random(4)
if (randomArrow2 == 0) {
basic.showLeds(`
. . # . .
. # # # .
# # # # #
. . # . .
. . # . .
`, 400)
} else if (randomArrow2 == 1) {
basic.showLeds(`
. . # . .
. . # . .
# # # # #
. # # # .
. . # . .
`, 400)
}
else if (randomArrow2 == 2) {
basic.showLeds(`
. . # . .
. . # # .
# # # # #
. . # # .
. . # . .
`, 400)
}
else if (randomArrow2 == 3) {
basic.showLeds(`
. . # . .
. # # . .
# # # # #
. # # . .
. . # . .
`, 400)
}
})
```
### ~avatar avatar
Excellent, you're ready to continue with the [challenges](/microbit/lessons/spinner/challenges)!
### ~

View File

@ -0,0 +1,156 @@
# spinner challenges
create an arrow that randomly points to a player. #docs
## Before we get started
Complete the following guided tutorial:
* [tutorial](/microbit/lessons/spinner/tutorial)
At the end of the tutorial, click `keep editing`. Your code should look like this:
```
input.onGesture(Gesture.Shake, () => {
let randomArrow = Math.random(4)
if (randomArrow == 0) {
basic.plotImage(`
. . # . .
. # # # .
# # # # #
. . # . .
. . # . .
`)
}
if (randomArrow == 1) {
basic.plotImage(`
. . # . .
. . # . .
# # # # #
. # # # .
. . # . .
`)
}
if (randomArrow == 2) {
basic.plotImage(`
. . # . .
. . # # .
# # # # #
. . # # .
. . # . .
`)
}
if (randomArrow == 3) {
basic.plotImage(`
. . # . .
. # # . .
# # # # #
. # # . .
. . # . .
`)
}
})
```
### Challenge 1
Modify the random number generator so that it can include new arrows we will create in the next challenge.
```
input.onGesture(Gesture.Shake, () => {
let randomArrow1 = Math.random(8) // ***
// **. . .**
if (randomArrow1 == 4) {
basic.plotImage(`
# # # # .
# # # . .
# # # . .
# . . # .
. . . . #
`)
}
if (randomArrow1 == 5) {
basic.plotImage(`
. # # # #
. . # # #
. . # # #
. # . # #
# . . . .
`)
}
if (randomArrow1 == 6) {
basic.plotImage(`
# . . . .
. # . . #
. . # # #
. . # # #
. # # # #
`)
}
if (randomArrow1 == 7) {
basic.plotImage(`
. . . . #
# . . # .
# # # . .
# # # . .
# # # # .
`)
}
})
```
* Do **not** run the code yet because it will not work until you have conditions for every random number.
### Challenge 2
Let's add four more arrows that point diagonally.
```
input.onGesture(Gesture.Shake, () => {
let randomArrow2 = Math.random(4)
// **. . .**
if (randomArrow2 == 4) {
basic.plotImage(`
# # # # .
# # # . .
# # # . .
# . . # .
. . . . #
`) // ***
}
if (randomArrow2 == 5) {
basic.plotImage(`
. # # # #
. . # # #
. . # # #
. # . # #
# . . . .
`) // ***
}
if (randomArrow2 == 6) {
basic.plotImage(`
# . . . .
. # . . #
. . # # #
. . # # #
. # # # #
`) // ***
}
if (randomArrow2 == 7) {
basic.plotImage(`
. . . . #
# . . # .
# # # . .
# # # . .
# # # # .
`) // ***
}
})
```
* Run your code to see if it works as expected
### Challenge 3
Add some other arrows if there are more than 8 players.

View File

@ -0,0 +1,56 @@
# spinner quiz answers
a spin the BBC micro:bit game with the input on shake #math #random #docs #shake
## Name
## Directions
Use this activity document to guide your work in the [spinner tutorial](/microbit/lessons/spinner/tutorial).
Answer the questions while completing the tutorial. Pay attention to the dialogues!
## 1. Write the code that stores a random number between 0 and 3 into a local variable named 'random arrow'.
<br/>
```
let randomArrow = Math.random(4)
```
## 2. Write the if statement that will display this down arrow from your code. Hint- This occurs if the local variable 'random arrow' returns 1.
![](/static/mb/lessons/spinner-0.png)
<br/>
```
if (randomArrow == 1) {
basic.plotImage(`
. . # . .
. . # . .
# # # # #
. # # # .
. . # . .
`)
}
```
## 3. Write the if statement that will display this right arrow. Hint- This occurs if the local variable 'random arrow' returns 2.
![](/static/mb/lessons/spinner-1.png)
<br />
```
if (randomArrow == 2) {
basic.plotImage(`
. . # . .
. . # # .
# # # # #
. . # # .
. . # . .
`)
}
```

View File

@ -0,0 +1,28 @@
# spinner quiz
a spin the BBC micro:bit game with the input on shake #math #random #docs #shake
## Name
## Directions
Use this activity document to guide your work in the [spinner tutorial](/microbit/lessons/spinner/tutorial).
Answer the questions while completing the tutorial. Pay attention to the dialogues!
## 1. Write the code that stores a random number between 0 and 3 into a local variable named 'random arrow'.
<br/>
## 2. Write the if statement that will display this down arrow from your code. Hint- This occurs if the local variable 'random arrow' returns 1.
![](/static/mb/lessons/spinner-0.png)
<br/>
## 3. Write the if statement that will display this right arrow. Hint- This occurs if the local variable 'random arrow' returns 2.
![](/static/mb/lessons/spinner-1.png)
<br />