pxt-calliope/docs/lessons/spinner/challenges.md

174 lines
3.2 KiB
Markdown
Raw Normal View History

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