-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimon_version2_cplus.py
164 lines (152 loc) · 4.51 KB
/
simon_version2_cplus.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
164
from m5stack import *
from m5ui import *
from uiflow import *
import time
import hat
setScreenColor(0x111111)
hat_Joystick3 = hat.get(hat.JOYSTICK)
atrouver = None
niveau = None
fdj = None
dir2 = None
sequence = None
high_score = None
action = None
i = None
k = None
continue2 = None
x = None
y = None
niveau_en_cours = M5TextBox(100, 219, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label0 = M5TextBox(42, 97, "Suite dans", lcd.FONT_Default, 0xFFFFFF, rotate=0)
nivea = M5TextBox(10, 218, "Niveau", lcd.FONT_Default, 0xFFFFFF, rotate=0)
action_a_effectuer = M5TextBox(19, 72, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
rebours = M5TextBox(42, 119, "Text", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)
label4 = M5TextBox(41, 149, "Text", lcd.FONT_DejaVu72, 0xFFFFFF, rotate=0)
sens = M5TextBox(45, 47, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
import random
from numbers import Number
def upRange(start, stop, step):
while start <= stop:
yield start
start += abs(step)
def downRange(start, stop, step):
while start >= stop:
yield start
start -= abs(step)
dir2 = ['^', 'v', '<', '>']
sequence = []
high_score = 0
niveau = 1
action = '-'
i = 0
k = 3
continue2 = 1
setScreenColor(0x000000)
niveau_en_cours.setText('')
label0.setColor(0x000000)
nivea.setColor(0x000000)
sens.setColor(0x000000)
while True:
M5Led.off()
niveau = 1
nivea.setColor(0x000000)
niveau_en_cours.setColor(0x000000)
while btnA.isReleased():
action_a_effectuer.setText('Appuyez sur A')
action = '-'
atrouver = random.randint(1, 4)
niveau_en_cours.setColor(0xffffff)
sequence = []
fdj = 0
while fdj != 1:
label4.setText('')
label0.setColor(0xff0000)
action_a_effectuer.setColor(0x000000)
rebours.setColor(0x990000)
k = 3
nivea.setColor(0xffffff)
niveau_en_cours.setText(str(niveau))
for count in range(3):
rebours.setText(str(k))
wait(0.5)
k = (k if isinstance(k, Number) else 0) + -1
label0.setColor(0x000000)
rebours.setColor(0x000000)
niveau_en_cours.setText(str(niveau))
M5Led.off()
label4.setText('')
atrouver = dir2[int(random.randint(1, 4) - 1)]
sequence.append(atrouver)
for i in (1 <= float(niveau)) and upRange(1, float(niveau), 1) or downRange(1, float(niveau), 1):
M5Led.off()
label4.setText(' ')
wait(0.2)
atrouver = sequence[int(i - 1)]
if atrouver == '^':
label4.setColor(0xff0000)
if atrouver == 'v':
label4.setColor(0xffff00)
if atrouver == '<':
label4.setColor(0x009900)
if atrouver == '>':
label4.setColor(0x33ccff)
label4.setText(str(sequence[int(i - 1)]))
M5Led.on()
wait(1)
action_a_effectuer.setColor(0xffffff)
action_a_effectuer.setText('repetez la sequence')
label4.setText('')
for i in (1 <= float(niveau)) and upRange(1, float(niveau), 1) or downRange(1, float(niveau), 1):
continue2 = 1
action = '-'
label4.setColor(0x000000)
while fdj == 0 and continue2 == 1:
M5Led.off()
x = hat_Joystick3.X
y = hat_Joystick3.Y
if y > 80:
action = '^'
label4.setColor(0xff0000)
M5Led.on()
if y < -20:
action = 'v'
label4.setColor(0xffff00)
M5Led.on()
if x < -20:
action = '<'
label4.setColor(0x009900)
M5Led.on()
if x > 80:
action = '>'
label4.setColor(0x33ccff)
M5Led.on()
sens.setText(str(sequence[int(i - 1)]))
wait(0.5)
label4.setText(str(action))
if action == sequence[int(i - 1)]:
action_a_effectuer.setText('ok')
wait(0.5)
continue2 = 0
action_a_effectuer.setText('suite')
else:
if action != '-':
action = '#'
i = (i if isinstance(i, Number) else 0) + 1
continue2 = 0
action_a_effectuer.setText('ko')
wait(0.5)
action_a_effectuer.setText('fin du jeu')
wait(1)
fdj = 1
label4.setText('')
continue2 = 1
if fdj == 1:
action_a_effectuer.setColor(0x000000)
else:
action_a_effectuer.setColor(0xffffff)
action_a_effectuer.setText('niveau suivant')
niveau = (niveau if isinstance(niveau, Number) else 0) + 1
wait(1)
action_a_effectuer.setColor(0xffffff)
wait_ms(2)