2016-03-26 00:47:20 +01:00
|
|
|
# spinner challenges
|
|
|
|
|
|
|
|
Create an arrow that randomly points to a player.
|
|
|
|
|
|
|
|
## Before we get started
|
|
|
|
|
2016-04-13 17:27:45 +02:00
|
|
|
Complete the following [guided tutorial](/lessons/spinner/activity), your code should look like this:
|
2016-03-26 00:47:20 +01:00
|
|
|
|
2016-03-31 00:11:05 +02:00
|
|
|
```blocks
|
|
|
|
input.onGesture(Gesture.Shake, () => {
|
2018-06-01 20:42:38 +02:00
|
|
|
let randomArrow = Math.randomRange(0, 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
|
|
|
|
2017-09-07 22:42:08 +02:00
|
|
|
## Challenge 1
|
2016-03-26 00:47:20 +01:00
|
|
|
|
|
|
|
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, () => {
|
2018-06-01 20:42:38 +02:00
|
|
|
let randomArrow = Math.randomRange(0, 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.
|
|
|
|
|
2017-09-07 22:42:08 +02:00
|
|
|
## Challenge 2
|
2016-03-26 00:47:20 +01:00
|
|
|
|
2016-03-31 00:11:05 +02:00
|
|
|
Let's add more arrows that point diagonally.
|
|
|
|
|
|
|
|
|
|
|
|
```blocks
|
|
|
|
input.onGesture(Gesture.Shake, () => {
|
2018-06-01 20:42:38 +02:00
|
|
|
let randomArrow = Math.randomRange(0, 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
|
|
|
|
|
2017-09-07 22:42:08 +02:00
|
|
|
## Challenge 3
|
2016-03-26 00:47:20 +01:00
|
|
|
|
|
|
|
Add some other arrows if there are more than 8 players.
|
|
|
|
|