-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
400 lines (338 loc) · 13.4 KB
/
main.py
File metadata and controls
400 lines (338 loc) · 13.4 KB
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
# Created by: Bob van den Berg
# escape room garage:
# Via Cem & Samantha van de Molengraft
# Karlijn en Jemma
# It should:
# 1 - It should be full screen on a laptop
# 2 - There should be a beep (sound) every 15 seconds, this will indicate that the participant has to press enter, within a 1 second time window.
# 3 - This should be repeated 7 times
# 4 - If done correctly, the screen should change to green and should show a calculation. There will be a 2 minute time window to type in the correct code
# 5 - If not done correctly (wrong code or in the previous step a beep is missed), the program should reset and start over again.
# TODO 1: Do something if total_seconds left <= 0. Like display text YOU FAIL
# TODO 2: Text input and open website if correct code is inputted.
# #!/usr/bin/python3
# import time
# import playsound
# from pygame.locals import *
# from sys import exit
# import pygame_textinput
# import webbrowser
# from threading import Timer
# from pynput.keyboard import Key, Controller
# !/usr/bin/python3
import time
import webbrowser
from sys import exit
from threading import Timer
import playsound
from pygame.locals import *
from pynput.keyboard import Key, Controller
from pygame_functions import *
import pygame_textinput
# THIS IS TO STOP ALT TAB OR OTHER KEYS TO BE PRESSED
# https://stackoverflow.com/questions/39110800/disable-alttab-combination-on-tkinter-app
# install from: https://sourceforge.net/projects/pyhook/
# import pyHook
keyboard = Controller()
# Time constants
TIME_TO_PAUSE = 4
# Different color constants
BLACK = (0, 0, 0)
RED = (255, 0, 0)
RED_ORANGE = (255, 80, 0)
ORANGE = (255, 160, 0)
ORANGE_YELLOW = (255, 200, 0)
YELLOW = (255, 255, 0)
YELLOW_GREEN = (160, 255, 0)
GREENISH = (80, 255, 0)
GREEN = (0, 255, 0)
# THIS IS FOR STARTING THE GAME INTRODUCTION
background_color = RED
INTRODUCTION_TEXT = "Here will come an introduction text"
pygame.init()
screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
pygame.display.set_caption('PRESS ENTER TO START')
screen.fill(background_color)
font = pygame.font.SysFont('Consolas', 20)
starting_text = "PRESS ENTER TO CONTINUE. LISTEN CAREFULLY"
screen.blit(
font.render(starting_text.rjust(3), True, (0, 0, 0)),
(400, screen.get_height() // 2))
pygame.display.update()
starting = True
while starting == True:
for event in pygame.event.get():
if event.type == KEYDOWN:
if event.key == K_RETURN:
starting = False
screen.fill(background_color)
text1 = 'You are an emergency team, brought together to save Disrupted Ltd.'
text2 = 'The business is in big trouble.'
text3 = 'The CEO has fled because the pressure was too much.'
text4 = 'Business processes, products and the workforce need a complete transformation to survive and beat competition.'
text5 = 'There are so many questions. Too many paths. What to automate?'
text6 = 'How to organise the workforce? Where does the business sit in the market?'
text7 = 'It’s overwhelming but essential to solve these challenges, right now.'
text8 = 'The business could not pay its employees salaries last month.'
text9 = 'This month they will walk out it their salaries aren’t paid.'
text10 = 'Today, it’s payday.'
text11 = 'You have 1 hour to make sure you are ready for the future of work and they are paid.'
text12 = 'If you fail... the company will go bankrupt and you’ll all lose your jobs!'
text13 = 'Good Luck'.rjust(3)
text14 = "PRESS ENTER TO CONTINUE"
screen.blit(
font.render(text1.rjust(3), True, (0, 0, 0)),
(400, screen.get_height() // 2 - 120))
screen.blit(
font.render(text2.rjust(3), True, (0, 0, 0)),
(400, screen.get_height() // 2 - 100))
screen.blit(
font.render(text3.rjust(3), True, (0, 0, 0)),
(400, screen.get_height() // 2 - 80))
screen.blit(
font.render(text4.rjust(3), True, (0, 0, 0)),
(400, screen.get_height() // 2 - 60))
screen.blit(
font.render(text5.rjust(3), True, (0, 0, 0)),
(400, screen.get_height() // 2 - 40))
screen.blit(
font.render(text6.rjust(3), True, (0, 0, 0)),
(400, screen.get_height() // 2 - 20))
screen.blit(
font.render(text7.rjust(3), True, (0, 0, 0)),
(400, screen.get_height() // 2))
screen.blit(
font.render(text8.rjust(3), True, (0, 0, 0)),
(400, screen.get_height() // 2 + 20))
screen.blit(
font.render(text9.rjust(3), True, (0, 0, 0)),
(400, screen.get_height() // 2 + 40))
screen.blit(
font.render(text10.rjust(3), True, (0, 0, 0)),
(400, screen.get_height() // 2 + 60))
screen.blit(
font.render(text11.rjust(3), True, (0, 0, 0)),
(400, screen.get_height() // 2 + 80))
screen.blit(
font.render(text12.rjust(3), True, (0, 0, 0)),
(400, screen.get_height() // 2 + 100))
screen.blit(
font.render(text13.rjust(3), True, (0, 0, 0)),
(400, screen.get_height() // 2 + 120))
screen.blit(
font.render(text14.rjust(3), True, (0, 0, 0)),
(400, screen.get_height() // 2 + 160))
pygame.display.update()
playsound.playsound("intro_emergency_team.mp3")
introduction = True
while introduction == True:
for event in pygame.event.get():
if event.type == KEYDOWN:
if event.key == K_RETURN:
introduction = False
# Solution
SECRET_CODE = "5147"
HANDCUFF_CODE = "0807"
URL = 'https://www.locked-game.nl/test/form.html'
# Settings for screen and initialisation of the game.
pygame.display.set_caption('ESCAPE ROOM')
background_color = RED
screen.fill(background_color)
counter = 0
background_color = RED
screen.fill(background_color)
clock = pygame.time.Clock()
pygame.time.set_timer(pygame.USEREVENT, 1000)
font = pygame.font.SysFont('Consolas', 50)
textinput = pygame_textinput.TextInput()
# INPUT BOX
input_box = pygame.Rect(100, 100, 140, 32)
color_inactive = pygame.Color('lightskyblue3')
color_active = pygame.Color('dodgerblue2')
color = color_inactive
active = False
text = '0'.rjust(3)
done = False
frame_count = 0
FRAME_RATE = 30
MINUTES_LEFT = 59
SECONDS_LEFT = 4
START_TIME = 3600
INTERVAL = 15
frame_count_code_timer = 0
START_VALUE_FOR_COUNTER = 0
failed_tries_counter = 0
TIME_OPEN_FOR_INPUT_CODE = 120 # seconds
sound_played = False
# Problems with the screen
# def reset_counter():
# counter = 0
# text = str(counter)
# background_color = RED
# screen.fill(background_color)
# screen.blit(
# font.render(text.rjust(3), True, (0, 0, 0)),
# (screen.get_width() // 2, screen.get_height() // 2))
# THIS IS TO STOP ALT TAB OR OTHER KEYS TO BE PRESSED
# def OnKeyboardEvent(event):
# if event.Key.lower() in [
# 'lwin', 'tab', 'lmenu', 'ctrl', 'alt', 'f', '1', '2', 'rcontrol',
# 'rmenu', 'lmenu', 'q', 'b'
# ]: #Keys to block:
# return False # block these keys
# # create a hook manager
# hm = pyHook.HookManager()
# # watch for all keyboard events
# hm.KeyDown = OnKeyboardEvent
# # set the hook
# hm.HookKeyboard()
def time_ran_out():
global out_of_time
print('You didn\'t answer in time')
out_of_time = True
# To enter out of the current window
keyboard.press(Key.enter)
# screen.fill(background_color)
# screen.blit(
# font.render(INTRODUCTION_TEXT, True, (0, 0, 0)),
# (screen.get_width() // 2, screen.get_height() // 2))
# pygame.display.update()
# input("press enter")
while True:
total_seconds = START_TIME - (frame_count // FRAME_RATE)
minutes = total_seconds // 60
seconds = total_seconds % 60
output_time_string = "Time left: {0:02}:{1:02}".format(minutes, seconds)
# If time is up, display: YOU LOSE
if total_seconds <= 0:
background_color = RED
screen.fill(background_color)
screen.blit(
font.render("YOU LOSE", True, (0, 0, 0)),
(screen.get_width() // 2, screen.get_height() // 2))
pygame.display.update()
for i in range(20):
time.sleep(5)
for event in pygame.event.get():
if total_seconds % INTERVAL == 0 and sound_played == False:
playsound.playsound("beep.mp3")
sound_played = True
elif total_seconds % INTERVAL != 0:
# Reset variables for every INTERVAL seconds
sound_played = False
enter_pressed_once = False
if event.type == QUIT:
pygame.quit()
exit()
elif event.type == pygame.locals.KEYDOWN:
# counter = START_VALUE_FOR_COUNTER # FOR TESTING PURPOSES OF CODE WINDOW
if counter > 7:
# Display text in middle of screen
# TODO FOR 2 MINUTES, ELSE RESET COUNTER TO 0
playsound.playsound("input_code.wav")
# Fix for bug when the code is not inputted after a two minute wait
counter = 0
text = str(counter)
background_color = RED
screen.fill(background_color)
pygame.display.update()
# Initialise timer for inputting the code.
out_of_time = False
t = Timer(TIME_OPEN_FOR_INPUT_CODE, time_ran_out)
t.start()
while out_of_time == False:
# frame_count_code_timer += 1
# clock.tick(FRAME_RATE)
screenSize(0, 0, fullscreen=True)
if failed_tries_counter == 0:
instructionLabel = makeLabel("Please enter code (Green Blue Red Black):", 40, 10,
10, "blue", "Agency FB",
"yellow")
showLabel(instructionLabel)
wordBox = makeTextBox(10, 80, 300, 0, "XXXX", 4, 24)
showTextBox(wordBox)
entry = textBoxInput(wordBox)
if entry == SECRET_CODE:
text = str(HANDCUFF_CODE)
background_color = GREEN
screen.fill(background_color)
font = pygame.font.SysFont('Consolas', 160)
# For big font centering added -160 and -60
screen.blit(
font.render(text.rjust(3), True, (0, 0, 0)),
(screen.get_width() // 2 - 160, screen.get_height() // 2 - 60))
# Open URL in new window, raising the window if possible. Also quit the pygame after the browser has opened.
pygame.display.update()
time.sleep(15)
webbrowser.open_new(URL)
pygame.quit()
quit()
else:
failed_tries_counter += 1
counter = START_VALUE_FOR_COUNTER
instructionLabel = makeLabel(f"Please enter code, failed tries: {failed_tries_counter} (Green Blue Red Black):", 40, 10,
10, "blue", "Agency FB",
"yellow")
showLabel(instructionLabel)
if out_of_time:
hideTextBox(wordBox)
print(
'this should appear only if input was given in 2 seconds...'
)
t.cancel()
counter = START_VALUE_FOR_COUNTER
# If pressed enter (can be another button) counter is increased by 1
elif event.key == pygame.K_RETURN and total_seconds % INTERVAL == 0 and counter <= 7:
print("enter pressed")
counter += 1
enter_pressed_once = False
text = str(counter)
elif event.key == pygame.K_RETURN and enter_pressed_once == True:
# If pressed multiple times per every INTERVAL seconds: Reset counter
counter = 0
text = str(counter)
background_color = RED
screen.fill(background_color)
screen.blit(
font.render(text.rjust(3), True, (0, 0, 0)),
(screen.get_width() // 2, screen.get_height() // 2))
else:
# If not pressed every INTERVAL seconds: Reset counter
counter = 0
text = str(counter)
background_color = RED
screen.fill(background_color)
screen.blit(
font.render(text.rjust(3), True, (0, 0, 0)),
(screen.get_width() // 2, screen.get_height() // 2))
pygame.display.update()
# For every counter change the color from red towards green.
if counter == 1:
background_color = RED_ORANGE
if counter == 2:
background_color = ORANGE
if counter == 3:
background_color = ORANGE_YELLOW
if counter == 4:
background_color = YELLOW
if counter == 5:
background_color = YELLOW_GREEN
if counter == 6:
background_color = GREENISH
if counter >= 7:
background_color = GREEN
screen.fill(background_color)
# Remove old text
screen.fill(background_color)
# Render text (counter + input)
screen.blit(
font.render(text.rjust(3), True, (0, 0, 0)),
(screen.get_width() // 2, screen.get_height() // 2))
# Render time left
screen.blit(font.render(output_time_string, True, (0, 0, 0)), (0, 0))
frame_count += 1
clock.tick(FRAME_RATE)
# pygame.display.update()
pygame.display.flip()
pygame.quit()
quit()