pxt-calliope/olddocs/lessons/spinner/challenges.md
Tom Ball f4eca66648 move lessons out of web site
will move select lessons back to "educators" section
2016-06-14 11:49:58 -04:00

174 lines
3.2 KiB
Markdown

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