Skip to content

Commit 5641d51

Browse files
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 <[email protected]>
1 parent f203ba4 commit 5641d51

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

docs/projects/reaction-time/code.md

+88
Original file line numberDiff line numberDiff line change
@@ -306,3 +306,91 @@ input.onPinPressed(TouchPin.P2, function () {
306306
}
307307
})
308308
```
309+
310+
## Extending the Extension
311+
312+
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.
313+
314+
```blocks
315+
input.onPinPressed(TouchPin.P0, function () {
316+
running = false
317+
false_start = false
318+
Winner = 0
319+
basic.showNumber(3)
320+
basic.showNumber(2)
321+
basic.showNumber(1)
322+
basic.clearScreen()
323+
basic.pause(1000 + randint(0, 2000))
324+
if (!(false_start)) {
325+
start = input.runningTime()
326+
running = true
327+
led.stopAnimation()
328+
basic.clearScreen()
329+
led.plotBrightness(randint(0, 4), randint(0, 4), 255)
330+
}
331+
})
332+
input.onPinPressed(TouchPin.P2, function () {
333+
if (running) {
334+
running = false
335+
end = input.runningTime()
336+
Winner = 2
337+
basic.showLeds(`
338+
. . . # #
339+
. . . # #
340+
. . . # #
341+
. . . # #
342+
. . . # #
343+
`)
344+
basic.pause(1000)
345+
basic.showNumber(end - start)
346+
} else if (Winner == 1) {
347+
348+
} else {
349+
false_start = true
350+
basic.showLeds(`
351+
. . . . .
352+
. . # . #
353+
. . . # .
354+
. . # . #
355+
. . . . .
356+
`)
357+
}
358+
})
359+
input.onPinPressed(TouchPin.P1, function () {
360+
if (running) {
361+
running = false
362+
end = input.runningTime()
363+
Winner = 1
364+
basic.showLeds(`
365+
# # . . .
366+
# # . . .
367+
# # . . .
368+
# # . . .
369+
# # . . .
370+
`)
371+
basic.pause(1000)
372+
basic.showNumber(end - start)
373+
} else if (Winner == 2) {
374+
375+
} else {
376+
false_start = true
377+
basic.showLeds(`
378+
. . . . .
379+
# . # . .
380+
. # . . .
381+
# . # . .
382+
. . . . .
383+
`)
384+
}
385+
})
386+
let Winner = 0
387+
let start = 0
388+
let end = 0
389+
let false_start = false
390+
let running = false
391+
running = false
392+
false_start = false
393+
end = 0
394+
start = 0
395+
Winner = 0
396+
```

0 commit comments

Comments
 (0)