Skip to content

Commit

Permalink
Extending the user interface to avoid the X after a winner is crowned.
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonSkotheimsvik authored Oct 13, 2024
1 parent 66593b8 commit 8dd5c49
Showing 1 changed file with 88 additions and 0 deletions.
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 false start X showing 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
```

0 comments on commit 8dd5c49

Please sign in to comment.