gPiOBox icon

Further - Steady! game code for micro:bit

gPiOBox | PRO | 10/17/17 08:27:08 AM UTC | 0 ⭐ | 1648 👁️ | Never ⏰ | []
Python |

970 B

|

None

|

0 👍

/

0 👎

"""
filename:gpio_mb_python_steady.py
Steady! game code for micro:bit
written by Trevor Olsson
© GPIO Support Services LTD MMXVII
more info at www.gpio.co.uk/steady
"""
from microbit import *
Lives=3
display.show(str(Lives))
while True:
    if button_a.is_pressed(): # Touch this to win
        display.show(Image.HAPPY)
        pin16.write_digital(1)
        pin13.write_digital(1)
        sleep(5000)
        pin16.write_digital(0)
        pin13.write_digital(0)
        break
    else:
        if button_b.is_pressed(): # Touch this 3 times to lose
            if Lives==1:
                pin15.write_digital(1)
                sleep(2000)
                pin15.write_digital(0)
                display.scroll("Game Lost")
                break
            else:
                Lives=Lives-1
                display.show(str(Lives))
                pin15.write_digital(1)
                sleep(1000)
                pin15.write_digital(0)
display.clear()

Comments