Extending the user interface to avoid the X after a winner is crowned. (#5995)
* Extending the user interface to avoid the X after a winner is crowned. * some small edits --------- Co-authored-by: Galen Nickel <gnickel@aquent.com>
This commit is contained in:
Родитель
f203ba4fef
Коммит
5641d51697
|
@ -306,3 +306,91 @@ input.onPinPressed(TouchPin.P2, function () {
|
|||
}
|
||||
})
|
||||
```
|
||||
|
||||
## Extending the Extension
|
||||
|
||||
One effect of the extension is the **X** for a false start shows for the person loosing the game. We can extend the code some more to avoid the **X** showing up on the person loosing the game. The following example uses a new variable to flag the winner and avoid the **X** after a winner is crowned.
|
||||
|
||||
```blocks
|
||||
input.onPinPressed(TouchPin.P0, function () {
|
||||
running = false
|
||||
false_start = false
|
||||
Winner = 0
|
||||
basic.showNumber(3)
|
||||
basic.showNumber(2)
|
||||
basic.showNumber(1)
|
||||
basic.clearScreen()
|
||||
basic.pause(1000 + randint(0, 2000))
|
||||
if (!(false_start)) {
|
||||
start = input.runningTime()
|
||||
running = true
|
||||
led.stopAnimation()
|
||||
basic.clearScreen()
|
||||
led.plotBrightness(randint(0, 4), randint(0, 4), 255)
|
||||
}
|
||||
})
|
||||
input.onPinPressed(TouchPin.P2, function () {
|
||||
if (running) {
|
||||
running = false
|
||||
end = input.runningTime()
|
||||
Winner = 2
|
||||
basic.showLeds(`
|
||||
. . . # #
|
||||
. . . # #
|
||||
. . . # #
|
||||
. . . # #
|
||||
. . . # #
|
||||
`)
|
||||
basic.pause(1000)
|
||||
basic.showNumber(end - start)
|
||||
} else if (Winner == 1) {
|
||||
|
||||
} else {
|
||||
false_start = true
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. . # . #
|
||||
. . . # .
|
||||
. . # . #
|
||||
. . . . .
|
||||
`)
|
||||
}
|
||||
})
|
||||
input.onPinPressed(TouchPin.P1, function () {
|
||||
if (running) {
|
||||
running = false
|
||||
end = input.runningTime()
|
||||
Winner = 1
|
||||
basic.showLeds(`
|
||||
# # . . .
|
||||
# # . . .
|
||||
# # . . .
|
||||
# # . . .
|
||||
# # . . .
|
||||
`)
|
||||
basic.pause(1000)
|
||||
basic.showNumber(end - start)
|
||||
} else if (Winner == 2) {
|
||||
|
||||
} else {
|
||||
false_start = true
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
# . # . .
|
||||
. # . . .
|
||||
# . # . .
|
||||
. . . . .
|
||||
`)
|
||||
}
|
||||
})
|
||||
let Winner = 0
|
||||
let start = 0
|
||||
let end = 0
|
||||
let false_start = false
|
||||
let running = false
|
||||
running = false
|
||||
false_start = false
|
||||
end = 0
|
||||
start = 0
|
||||
Winner = 0
|
||||
```
|
||||
|
|
Загрузка…
Ссылка в новой задаче