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

microbit recation game #111

Closed
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
98 changes: 98 additions & 0 deletions examples/reactonGame.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
from microbit import *

def countDown(x):
while x > 0:
msg = "%d" % (x)
display.print(msg)
sleep(500)
x = x - 1
display.clear()


def spin(direction):
if direction is "b":
display.print(Image.ARROW_N)
sleep(100)
display.print(Image.ARROW_NE)
sleep(100)
display.print(Image.ARROW_E)
sleep(100)
display.print(Image.ARROW_SE)
sleep(100)
display.print(Image.ARROW_S)
sleep(100)
display.print(Image.ARROW_SW)
sleep(100)
display.print(Image.ARROW_W)
sleep(100)
display.print(Image.ARROW_NW)
sleep(100)
display.print(Image.ARROW_N)
sleep(100)
display.print(Image.ARROW_NE)
sleep(100)
display.print(Image.ARROW_E)
sleep(100)
flash("b")

if direction is "a":
display.print(Image.ARROW_N)
sleep(100)
display.print(Image.ARROW_NW)
sleep(100)
display.print(Image.ARROW_W)
sleep(100)
display.print(Image.ARROW_SW)
sleep(100)
display.print(Image.ARROW_S)
sleep(100)
display.print(Image.ARROW_SE)
sleep(100)
display.print(Image.ARROW_E)
sleep(100)
display.print(Image.ARROW_NE)
sleep(100)
display.print(Image.ARROW_N)
sleep(100)
display.print(Image.ARROW_NW)
sleep(100)
display.print(Image.ARROW_W)
sleep(100)
flash("a")

def flash(direction):
if direction is "b":
a = 10
while a > 0:
display.print(Image.ARROW_E)
sleep(200)
display.clear()
sleep(200)
a = a - 1
if direction is "a":
a = 10
while a > 0:
display.print(Image.ARROW_W)
sleep(200)
display.clear()
sleep(200)
a = a - 1



countDown(5)
howLong = random(7000)
sleep(howLong)

while (not button_a.is_pressed()) and (not button_b.is_pressed()):
display.print(Image.HAPPY)
sleep(1)

if button_a.is_pressed():
spin("a")
sleep(1000)
else:
spin("b")
sleep(1000)

display.clear()