Skip to content

Instantly share code, notes, and snippets.

@itkovian itkovian/prs.py
Created Nov 23, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.