174 lines
3.3 KiB
Markdown
Raw Normal View History

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