This is a FUN talking Heads Or Tails game for the official BBC micro:bit V2 where you play with get to play with our little talking friend!
*PLUG IN USB CABLE TO COMPUTER AND DEVICE
import gc
import time
from random import randint
from microbit import display, Image, button_a, button_b
from speech import say
SPEED = 95
result = randint(0, 1)
display.show(Image.MEH)
say('Let us play heads or tails.', speed=SPEED)
time.sleep(1)
say('Press button Ayy if you want to guess heads.', speed=SPEED)
time.sleep(1)
say('Press button B if you want to guess tails.', speed=SPEED)
while True:
if button_a.is_pressed():
if result == 0:
display.show(Image.HAPPY)
say('Hooray!', speed=SPEED)
say('You guessed heads and you were right.', speed=SPEED)
say('You won!', speed=SPEED)
say('Press the RESET button to play again!', speed=SPEED)
break
else:
display.show(Image.SAD)
say('Sorry!', speed=SPEED)
say('When I flipped my little coin it came up tails.', speed=SPEED)
say('Better luck next time!', speed=SPEED)
say('Press the RESET button to play again!', speed=SPEED)
break
if button_b.is_pressed():
if result == 1:
display.show(Image.HAPPY)
say('Hooray!', speed=SPEED)
say('You guessed tails and you were right.', speed=SPEED)
say('You won!', speed=SPEED)
say('Press the RESET button to play again!', speed=SPEED)
break
else:
display.show(Image.SAD)
say('Sorry!', speed=SPEED)
say('When I flipped my little coin it came up heads.', speed=SPEED)
say('Better luck next time!', speed=SPEED)
say('Press the RESET button to play again!', speed=SPEED)
break
When you plug in the micro:bit our little friend will introduce the game and give you some basic instructions. If you would like to guess heads press the A button and if you would like to guess tails press the B button. Once you play and you would like to play again simply press the reset button on the back of the micro:bit.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.