Microbit Code03:Rock Scissors Paper
From artserver wiki
from microbit import *
from random import choice
rock = Image('0000:09990:09990:09990:00000')
paper = Image('99999:90009:90009:90009:99999')
sissors_open = Image('00009:09090:00900:09090:00009')
sissors_closed = Image('000000:09000:00999:09000:00000')
sissors = [sissors_open, sissors_closed]
possibilities = [rock, sissors, paper]
winlist = [[rock, sissors],
[paper, rock],
[sissors, paper]] # [winner, looser]
def animate(img):
print(type(img) )
if type(img) == list:
return True
else:
return False
def whowins(a, b):
if [a, b] in winlist:
return a
elif [b, a] in winlist:
return b
else:
return '='
a_presses = 0
b_presses = 0
choices = {'a': '', 'b': ''} # store the choices if 1 game
while True:
if button_a.is_pressed():
if a_presses is 0:
choices['a'] = choice(possibilities)
display.show(choices['a'], wait=False, delay=200, loop=True)
a_presses += 1
elif button_b.is_pressed():
if b_presses is 0:
choices['b'] = choice(possibilities)
display.show(choices['b'], wait=False, delay=200, loop=True )
b_presses += 1
else:
if choices['a'] and choices['b']: # both A & B made their choice
display.show('?')
sleep(1000)
won = whowins(choices['a'], choices['b'])
display.show(won, wait=False, delay=200, loop=True)
# calculate who won
choices = {'a': '', 'b': ''}
sleep(2000)
elif not choices['a'] and choices['b'] : # A's turn
display.show(Image.ARROW_W)
elif not choices['b'] and choices['a']: # B's turn
display.show(Image.ARROW_E)
else:
display.show(Image.ARROW_W)
a_presses = 0
b_presses = 0
# TODO: total score: can either use
# * 25 rounds, using the 25 leds as score indicators
# * A & B simultaneus click == show scores
Code Notes 2019
... more about "Microbit Code03:Rock Scissors Paper"