-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimonClass.py
66 lines (56 loc) · 1.3 KB
/
SimonClass.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
59
60
61
62
63
64
65
66
import RPi.GPIO as GPIO
from GPIO import LED, Button
import random
import math
from time import sleep as wait
class SimonGame(object):
def __init__(self, leds, buttons):
self.NUM_OF_THINGS = len(leds)
#let's create the LEDs
self.LED = [(lambda x: LED(leds[x]))(x) for x in range(len(leds))]
self.Button = [(lambda x: Button(buttons[x]))(x) for x in range(len(buttons))]
#now for some variables
self.level = 1
self.pattern = []
alive = True
def start(self):
self.startSequence()
self.score = 0
self.gameIndex = 0
def createLevel(self):
self.pattern.append(random.randint(0,3))
def startSequence(self):
for i in range(0,self.NUM_OF_THINGS * 2):
LED = self.LED[i%self.NUM_OF_THINGS]
LED.turnOn()
wait(0.1)
LED.turnOff()
wait(0.15)
self.turnOnLEDs()
wait(1)
self.turnOffLEDs()
def cleanup(self):
for LED in self.LED:
LED.cleanup()
for Button in self.Button:
Button.cleanup()
def gameOver(self):
for i in range(3):
self.turnOnLEDs()
wait(1)
self.turnOffLEDs()
wait(1)
def turnOnLEDs(self):
for LED in self.LED:
LED.turnOn()
def turnOffLEDs(self):
for LED in self.LED:
LED.turnOff()
def flashPattern(self, pattern):
for flash in pattern:
print flash
LED = self.LED[flash]
LED.turnOn()
wait(0.3)
LED.turnOff()
wait(0.2)