-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.py
More file actions
346 lines (269 loc) · 9 KB
/
Copy pathgame.py
File metadata and controls
346 lines (269 loc) · 9 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
import pygame
import random
import time
# Initialize Pygame
pygame.init()
# Set up the screen
screen_width = 800
screen_height = 600
screen = pygame.display.set_mode((screen_width, screen_height))
pygame.display.set_caption("Strategem Game")
# Colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
RED = (255, 0, 0)
# Define the strategem combos
strategem_data = """
Machine Gun
Down, Left, Down, Up, Right
Anti-Material Rifle
Down, Left, Right, Up, Down
Stalwart
Down, Left, Down, Up, Up, Left
Expendable Anti-Tank
Down, Down, Left, Up, Right
Recoilless Rifle
Down, Left, Right, Right, Left
Flamethrower
Down, Left, Up, Down, Up
Autocannon
Down, Left, Down, Up, Up, Right
Railgun
Down, Right, Left, Down, Up, Left, Right
Spear
Down, Down, Up, Down, Down
Orbital Gatling Barrage
Right, Down, Left, Up, Up
Orbital Airburst Strike
Right, Right, Right
Orbital 120MM HE Barrage
Right, Down, Left, Right, Down
Orbital 380MM HE Barrage
Right, Down, Up, Up, Left, Down, Down
Orbital Walking Barrage
Right, Right, Down, Left, Right, Down
Orbital Lasers
Right, Down, Up, Right, Down
Orbital Railcannon Strike
Right, Up, Down, Down, Right
Eagle Strafing Run
Up, Right, Right
Eagle Airstrike
Up, Right, Down, Right
Eagle Cluster Bomb
Up, Right, Down, Down, Right
Eagle Napalm Airstrike
Up, Right, Down, Up
Jump Pack
Down, Up, Up, Down, Up
Eagle Smoke Strike
Up, Right, Up, Down
Eagle 110MM Rocket Pods
Up, Right, Up, Left
Eagle 500KG Bomb
Up, Right, Down, Down, Down
Orbital Precision Strike
Right, Right, Up
Orbital Gas Strike
Right, Right, Down, Right
Orbital EMS Strike
Right, Right, Left, Down
Orbital Smoke Strike
Right, Right, Down, Up
HMG Emplacement
Down, Up, Left, Right, Right, Left
Shield Generation Relay
Down, Up, Left, Down, Right, Right
Tesla Tower
Down, Up, Right, Up, Left, Right
Anti-Personnel Minefield
Down, Left, Up, Right
Supply Pack
Down, Left, Down, Up, Up, Down
Grenade Launcher
Down, Left, Up, Left, Down
Laser Cannon
Down, Left, Down, Up, Left
Incendiary Mines
Down, Left, Left, Down
Guard Dog Rover
Down, Up, Left, Up, Right, Right
Ballistic Shield Backpack
Down, Left, Up, Up, Right
Arc thrower
Down, Right, Up, Left, Down
Shield Generator Pack
Down, Up, Left, Right, Left, Right
Machine Gun Sentry
Down, Up, Right, Right, Up
Gatling Sentry
Down, Up, Right, Left
Mortar Sentry
Down, Up, Right, Right, Down
Guard Dog
Down, Up, Left, Up, Right, Down
Autocannon Sentry
Down, Up, Right, Up, Left, Up
Rocket Sentry
Down, Up, Right, Right, Left
EMS Mortar Sentry
Down, Down, Up, Up, Left
"""
# Parse combo data
combo_list = strategem_data.strip().split("\n\n")
combos = {}
for strategem_data in combo_list:
lines = strategem_data.strip().split("\n")
name = lines[0]
combination = [key.strip() for key in lines[1].split(",")]
combos[name] = combination
# Timing variables
time_limit = 15 # seconds per round
start_time = 0
time_remaining = time_limit
# Scoring variables
score = 0
highscore = 0
# Load a font
font_path = "Arial.ttf"
font = pygame.font.Font(font_path, 36)
# Define arrow symbols using Unicode characters
ARROW_SYMBOLS = {"Up": "↑", "Down": "↓", "Left": "←", "Right": "→"}
# Function to generate a new combo with arrow symbols
def generate_combo():
while True:
combo_name = random.choice(list(combos.keys()))
combo = combos[combo_name]
if combo:
combo_with_arrows = [key for key in combo]
return combo_name, combo_with_arrows
# Function to display text on the screen
def draw_text(text, x, y, color=BLACK):
text_surface = font.render(text, True, color)
screen.blit(text_surface, (x, y))
# Game state variables
game_started = False
combo_started = False
running = True
game_over = False
incorrect_key_time = 0
incorrect_key = False
incorrect_key_duration = 0.5 # in seconds
# Main game loop
combo_name, combo = "", []
original_combos = {} # Dictionary to store original combos
while running:
# Clear the screen
screen.fill(WHITE)
# Check for events
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.KEYDOWN:
if not game_started:
# Start the game if Enter is pressed
if event.key == pygame.K_RETURN:
game_started = True
combo_started = True
# Start the timer and generate the first combo
start_time = time.time()
combo_name, combo = generate_combo()
original_combos[combo_name] = list(combo) # Store original combo
print("Game started!")
elif game_over:
# Restart the game if y is pressed
if event.key == pygame.K_y:
game_over = False
game_started = False
score = 0
start_time = 0
time_remaining = time_limit
print("Game restarted!")
# Close the game if n is pressed
elif event.key == pygame.K_n:
running = False
# if highscore is greater than 0, save it to a file
if highscore > 0:
with open("highscore.txt", "a") as file:
file.write(
f"Highscore: {highscore} | Date: {time.asctime()}\n"
)
file.close()
else:
# Check if the pressed key matches the next key in the combo
if event.key in [pygame.K_w, pygame.K_s, pygame.K_a, pygame.K_d]:
key = ""
if event.key == pygame.K_w:
key = "Up"
elif event.key == pygame.K_s:
key = "Down"
elif event.key == pygame.K_a:
key = "Left"
elif event.key == pygame.K_d:
key = "Right"
if len(combo) > 0 and key == combo[0]:
combo.pop(0) # Remove the matched key
# add 1 second to the timer
if len(combo) == 0: # If all keys matched
score += 1
combo_name, combo = generate_combo()
# Store original combo
original_combos[combo_name] = list(combo)
# start_time = time.time() # Reset the timer
# add to the timer
start_time += 2
combo_started = True
print("Correct! Next combo:")
print(combo_name)
print(combo)
else: # Incorrect key
if combo_started:
print("Incorrect key! Combo reset.")
# Reset combo to original state
combo = list(original_combos[combo_name])
# Remove from the timer
start_time -= 3
incorrect_key = True
incorrect_key_time = (
time.time()
) # Start the timer for incorrect key message
# Display the "Incorrect key" message for 0.5 seconds
if incorrect_key and time.time() - incorrect_key_time < incorrect_key_duration:
draw_text("Incorrect key!", 200, 400, RED)
else:
incorrect_key = False # Reset incorrect key flag
# Check if the game has started
if not game_started:
draw_text("Press Enter to start the game", 200, 200)
elif game_over:
# Display final score and prompt to restart the game
draw_text("Game Over!", 300, 200, RED)
draw_text("Final Score: " + str(score), 300, 250, RED)
if score > highscore:
highscore = score # Update highscore only if current score is higher
# Display highscore
draw_text("Highest: " + str(highscore), 10, 90)
draw_text("Restart? (y/n)", 280, 300, RED)
else:
# Check the time
current_time = time.time()
time_remaining = max(0, time_limit - (current_time - start_time))
if time_remaining == 0:
# Time's up, end the game
game_over = True
print("Time's up! Game over.")
# Display the score and time remaining
draw_text("Score: " + str(score), 10, 10)
draw_text("Time: " + str(round(time_remaining)), 10, 50)
# Display the name of the current combo
draw_text("Combo: " + combo_name, 10, 130)
# Display the remaining keys for the current combo using arrow symbols
draw_text(
"Remaining Keys: " + " ".join([ARROW_SYMBOLS[key] for key in combo]),
10,
170,
)
# Update the display
pygame.display.flip()
# Quit Pygame
pygame.quit()