-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimon.py
58 lines (53 loc) · 1.48 KB
/
Simon.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from time import sleep as wait #for timing
from GPIO import LED, Button #my own GPIO device classes
from SimonClass import SimonGame
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
#creates game object with these pins
#first parameter passed is an array containing all LED pins, etc.
game = SimonGame([3, 5, 8, 10], [11, 13, 16, 18])
numOfThings = game.NUM_OF_THINGS
## LEDS:
#3: Top Left LED, 5: Top Right LED, 8: Bottom Right LED, 10: Bottom Left LED
## Buttons:
#11: Top Left Button, 13: Top Right Button, 16: Bottom Right Button, 18: Bottom Left Button
game.turnOffLEDs()
#stuff to start the game
game.start()
wait(1)
#loop
try:
#forever
while True:
position = 0
game.createLevel()
game.flashPattern(game.pattern)
#play level
i = 0
while position < len(game.pattern):
goal = game.pattern[position]
#check if it's the right one, if it is, move on to next position, else game over.
buttonpos = i%numOfThings
button = game.Button[buttonpos]
if button.isPressed():
game.LED[buttonpos].turnOn()
if game.Button[goal].isPressed():
position += 1
print "did a thing"
else:
game.gameOver()
print "fail " + str(button)
raise SystemExit
#needs to start the game from the beginning somehow...
button.waitUntilNotPressed()
game.LED[buttonpos].turnOff()
i += 1
print "LEVEL COMPLETE"
game.level += 1
game.turnOffLEDs()
wait(1)
except KeyboardInterrupt:
GPIO.cleanup()
except SystemExit:
GPIO.cleanup()