Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extending the user interface to avoid the X after a winner is crowned. #5995

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions docs/projects/reaction-time/code.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Loading