-
Notifications
You must be signed in to change notification settings - Fork 0
/
electronicDie.py
163 lines (148 loc) · 4.52 KB
/
electronicDie.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
from sense_hat import SenseHat
from random import randint
import time
class ElectronicDie:
dieFaces = []
def __init__(self):
super().__init__()
SenseHat().low_light = True
self.dieFaces.append(self.die1())
self.dieFaces.append(self.die2())
self.dieFaces.append(self.die3())
self.dieFaces.append(self.die4())
self.dieFaces.append(self.die5())
self.dieFaces.append(self.die6())
#Method call for just using the Dice only
def runDie(self):
sense = SenseHat()
faces = self.dieFaces.copy()
exit = False
while exit==False:
for event in sense.stick.get_events():
# Check for when the jostick is pressed
if event.action == "pressed":
if event.direction == "right":
exit = True;
sense.show_message("Back to menu")
return
acceleration = sense.get_accelerometer_raw()
x = acceleration['x']
y = acceleration['y']
z = acceleration['z']
x = abs(x)
y = abs(y)
z = abs(z)
if x > 3 or y > 3 or z > 3:
opt = randint(1,6)
sense.set_pixels(faces[opt-1])
time.sleep(3)
sense.clear()
else:
sense.clear()
#time.sleep(3)
#Method call for game.py to use Dice
def gameDie(self):
sense = SenseHat()
faces = self.dieFaces.copy()
exit = False
while exit==False:
acceleration = sense.get_accelerometer_raw()
x = acceleration['x']
y = acceleration['y']
z = acceleration['z']
x = abs(x)
y = abs(y)
z = abs(z)
if x > 3 or y > 3 or z > 3:
opt = randint(1,6)
sense.set_pixels(faces[opt-1])
time.sleep(3)
sense.clear()
exit = True
return opt
else:
sense.clear()
def die1(self):
w = (255, 255, 255)
o = (0, 0, 0)
display = [
o, o, o, o, o, o, o, o,
o, o, o, o, o, o, o, o,
o, o, o, o, o, o, o, o,
o, o, o, w, w, o, o, o,
o, o, o, w, w, o, o, o,
o, o, o, o, o, o, o, o,
o, o, o, o, o, o, o, o,
o, o, o, o, o, o, o, o
]
return display
def die2(self):
w = (255, 255, 255)
o = (0, 0, 0)
display = [
o, o, o, o, o, o, o, o,
o, o, o, o, o, w, w, o,
o, o, o, o, o, w, w, o,
o, o, o, o, o, o, o, o,
o, o, o, o, o, o, o, o,
o, w, w, o, o, o, o, o,
o, w, w, o, o, o, o, o,
o, o, o, o, o, o, o, o
]
return display
def die3(self):
w = (255, 255, 255)
o = (0, 0, 0)
display = [
o, o, o, o, o, o, w, w,
o, o, o, o, o, o, w, w,
o, o, o, o, o, o, o, o,
o, o, o, w, w, o, o, o,
o, o, o, w, w, o, o, o,
o, o, o, o, o, o, o, o,
w, w, o, o, o, o, o, o,
w, w, o, o, o, o, o, o
]
return display
def die4(self):
w = (255, 255, 255)
o = (0, 0, 0)
display = [
o, o, o, o, o, o, o, o,
o, w, w, o, o, w, w, o,
o, w, w, o, o, w, w, o,
o, o, o, o, o, o, o, o,
o, o, o, o, o, o, o, o,
o, w, w, o, o, w, w, o,
o, w, w, o, o, w, w, o,
o, o, o, o, o, o, o, o
]
return display
def die5(self):
w = (255, 255, 255)
o = (0, 0, 0)
display = [
o, w, w, o, o, w, w, o,
o, w, w, o, o, w, w, o,
o, o, o, o, o, o, o, o,
o, o, o, w, w, o, o, o,
o, o, o, w, w, o, o, o,
o, o, o, o, o, o, o, o,
o, w, w, o, o, w, w, o,
o, w, w, o, o, w, w, o
]
return display
def die6(self):
w = (255, 255, 255)
o = (0, 0, 0)
display = [
o, w, w, o, o, w, w, o,
o, w, w, o, o, w, w, o,
o, o, o, o, o, o, o, o,
o, w, w, o, o, w, w, o,
o, w, w, o, o, w, w, o,
o, o, o, o, o, o, o, o,
o, w, w, o, o, w, w, o,
o, w, w, o, o, w, w, o
]
return display