Created
November 23, 2017 21:38
-
-
Save itkovian/0ddee1bb387a973b806c63bdb50e06cf to your computer and use it in GitHub Desktop.
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
from microbit import * | |
import random | |
import radio | |
bss = [0, 1, 2] | |
score = 0 | |
radio.on() | |
radio.config( | |
power=4, | |
) | |
imgs = [ | |
Image( | |
'99999:' | |
'90009:' | |
'90009:' | |
'90009:' | |
'99999:' | |
), | |
Image( | |
'00000:' | |
'09990:' | |
'09990:' | |
'09990:' | |
'00000:' | |
), | |
Image( | |
'00099:' | |
'00900:' | |
'99000:' | |
'00900:' | |
'00099:' | |
) | |
] | |
shaken = False | |
def wins(me, other): | |
display.scroll("<" + str(me) + " " + str(other) + ">") | |
sleep(5000) | |
if me == other: | |
return False | |
if me < other: | |
return True | |
if me == 2 and other == 0: | |
return True | |
return False | |
# Write your code here :-) | |
while True: | |
display.show(str(score)) | |
if shaken: | |
display.set_pixel(0,0,9) | |
else: | |
display.set_pixel(4,0,9) | |
if accelerometer.was_gesture("shake"): | |
c = random.choice(bss) | |
display.show(imgs[c]) | |
shaken = True | |
sleep(5000) | |
while shaken: | |
if c == 0: | |
display.set_pixel(1, 3, 6) | |
else: | |
display.set_pixel(0, 4, 6) | |
radio.send(str(c)) | |
other = radio.receive() | |
if other: | |
if wins(c, int(other)): | |
score += 1 | |
shaken = False | |
display.set_pixel(0, 4, 0) | |
display.set_pixel(1, 3, 0) | |
sleep(1000) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment