-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Expand file tree
/
Copy pathsimon_says.py
More file actions
35 lines (30 loc) · 858 Bytes
/
simon_says.py
File metadata and controls
35 lines (30 loc) · 858 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from random import randrange
from microbit import Image, accelerometer, display, sleep
# Define left, stay still and right
directions = ["L", "O", "R"]
points = 0
# While the micro:bit is on
while True:
# Pick a random direction
direction = directions[randrange(3)]
display.show(direction)
# Sleep for a second (1000ms)
sleep(1000)
# Get the X-axis (left-right) tilt
acc_x = accelerometer.get_x()
# Determine direction
if acc_x < -200:
player_in = "L"
elif abs(acc_x) < 200:
player_in = "O"
elif acc_x > 200:
player_in = "R"
# Check win condition
if player_in == direction:
# Player's input is correct
points += 1
else:
display.scroll(points)
display.show(Image.SAD)
points = 0
sleep(1000)