2016-03-26 00:47:20 +01:00
# truth or dare activity
A multi-player game that forces each player to reveal a secret or something funny.
2017-09-07 22:42:08 +02:00
## ~avatar avatar
2016-03-26 00:47:20 +01:00
2016-05-27 00:24:10 +02:00
2016-03-26 00:47:20 +01:00
2016-11-02 01:44:37 +01:00
Welcome! This tutorial will teach how to program a game of truth or dare on the @boardname @. Let's get started!
2016-03-26 00:47:20 +01:00
2017-09-07 22:42:08 +02:00
## ~
2016-03-26 00:47:20 +01:00
Begin by using Show LEDs to create an "up-arrow" image, which will point to someone.
```blocks
basic.showLeds(`
. . # . .
. # # # .
# # # # #
. . # . .
. . # . .
`)
```
2016-11-02 01:44:37 +01:00
Now let's create a condition to know when button `A` is pressed so that we can display "truth" or "dare" on the @boardname @. We want the @boardname @ to randomly choose whether to display "truth" or display "dare". We can use accomplish this by using `pick random (1)` .
2016-03-26 00:47:20 +01:00
```blocks
basic.showLeds(`
. . # . .
. # # # .
# # # # #
. . # . .
. . # . .
`)
input.onButtonPressed(Button.A, () => {
2018-06-01 20:42:38 +02:00
let random = Math.randomRange(0, 2)
2016-03-26 00:47:20 +01:00
})
```
Now let's display the appropriate message for each scenario of `random` .
```blocks
basic.showLeds(`
. . # . .
. # # # .
# # # # #
. . # . .
. . # . .
`)
input.onButtonPressed(Button.A, () => {
2018-06-01 20:42:38 +02:00
let random = Math.randomRange(0, 2)
2016-03-26 00:47:20 +01:00
if (random == 0) {
basic.showString("TRUTH")
} else {
basic.showString("DARE")
}
})
```
Notice how the arrow didn't display again after pressing button `A` . Let's add a line of code that displays the arrow again.
```blocks
basic.showLeds(`
. . # . .
. # # # .
# # # # #
. . # . .
. . # . .
`)
input.onButtonPressed(Button.A, () => {
2018-06-01 20:42:38 +02:00
let random = Math.randomRange(0, 2)
2016-03-26 00:47:20 +01:00
if (random == 0) {
basic.showString("TRUTH")
} else {
basic.showString("DARE")
}
basic.showLeds(`
. . # . .
. # # # .
# # # # #
. . # . .
. . # . .
`)
})
```
* Run your program: Press button A!
2017-09-07 22:42:08 +02:00
## ~avatar avatar
2016-03-26 00:47:20 +01:00
2016-04-13 17:27:45 +02:00
Excellent, you're ready to continue with the [challenges ](/lessons/truth-or-dare/challenges )!
2016-03-26 00:47:20 +01:00
2017-09-07 22:42:08 +02:00
## ~
2016-03-26 00:47:20 +01:00