Last active
October 30, 2017 00:35
-
-
Save nbogie/0f209b5d61a3f61412d730a3be414407 to your computer and use it in GitHub Desktop.
micro:bit reaction game
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let startTime = 0 | |
let scoring = false | |
let playing = false | |
let winTime = 0 | |
input.onPinPressed(TouchPin.P0, () => { | |
startRound() | |
}) | |
function handleWin() { | |
winTime = input.runningTime() - startTime | |
basic.showNumber(winTime) | |
radio.sendNumber(winTime) | |
} | |
function foul() { | |
radio.sendNumber(-1) | |
basic.showIcon(IconNames.Angry) | |
} | |
function startRound() { | |
playing = false | |
scoring = false | |
basic.showNumber(3) | |
basic.showNumber(2) | |
basic.showNumber(1) | |
basic.showLeds(` | |
. . . . . | |
. . . . . | |
. . . . . | |
. . . . . | |
. . . . . | |
`) | |
basic.pause(Math.random(4001)) | |
playing = true | |
startTime = input.runningTime() | |
led.plot(Math.random(5), Math.random(5)) | |
} | |
input.onPinPressed(TouchPin.P1, () => { | |
if (playing) { | |
scoring = true | |
playing = false | |
basic.showLeds(` | |
. . # . . | |
. # . . . | |
# . . . . | |
. # . . . | |
. . # . . | |
`) | |
handleWin() | |
} else if (scoring) { | |
} else { | |
foul() | |
basic.showLeds(` | |
. . . . . | |
# . # . . | |
. # . . . | |
# . # . . | |
. . . . . | |
`) | |
} | |
}) | |
input.onPinPressed(TouchPin.P2, () => { | |
if (playing) { | |
scoring = true | |
playing = false | |
basic.showLeds(` | |
. . # . . | |
. . . # . | |
. . . . # | |
. . . # . | |
. . # . . | |
`) | |
handleWin() | |
} else if (scoring) { | |
} else { | |
basic.showLeds(` | |
. . . . . | |
. . # . # | |
. . . # . | |
. . # . # | |
. . . . . | |
`) | |
} | |
}) | |
radio.setGroup(44) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment