Created
April 24, 2018 22:47
-
-
Save will-moore/db0baf80ea40af964e3e263445b42c40 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Editor https://makecode.microbit.org/ | |
// Use 1 microbit as 'master' controller. Others act as 'moles', randomly showing image to hit. | |
// If hit (shake) while showing image, master microbit increments and shows score | |
let showing = false | |
let score = 0 | |
let master = false | |
input.onButtonPressed(Button.A, () => { | |
master = true | |
radio.sendString("start") | |
}) | |
radio.onDataPacketReceived( ({ receivedString }) => { | |
if (receivedString == "start") { | |
for (let index = 0; index <= 2; index++) { | |
basic.showNumber(3 - index) | |
basic.pause(1000) | |
} | |
basic.clearScreen() | |
while (true) { | |
basic.pause(Math.random(5001)) | |
showing = true | |
basic.showIcon(IconNames.Ghost) | |
basic.pause(500) | |
showing = false | |
basic.clearScreen() | |
} | |
} else if (receivedString == "hit") { | |
score += 1 | |
if (master) { | |
basic.showNumber(score) | |
} | |
} | |
}) | |
input.onGesture(Gesture.Shake, () => { | |
if (showing) { | |
showing = false | |
basic.showIcon(IconNames.No) | |
radio.sendString("hit") | |
} | |
}) | |
radio.setGroup(1) | |
game.setScore(0) | |
score = 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment