-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSource
More file actions
338 lines (275 loc) · 8.77 KB
/
Source
File metadata and controls
338 lines (275 loc) · 8.77 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
#This is a recreation of the "world's hardest game"
#The user must navigate a block outside a maze
#If the user touches another block, the cordinates of the block are reset
#There are two level, and the game automatically goes the the next level if the previous is beaten
#Part of the difficulty is to figure out what block you are
import keyboard # Importing modules
from turtle import*
import turtle
import time
screen = Screen()
def level1(): # Level one
def square(x,y): # Function to make a square
layer1.up()
layer1.goto(x-5,y-5)
layer1.down()
layer1.goto(x+5,y-5)
layer1.goto(x+5,y+5)
layer1.goto(x-5,y+5)
layer1.goto(x-5,y-5)
walls = Turtle() # Maze walls cordinates
walls.up()
walls.speed(0)
walls.goto(-400, 200)
walls.down()
walls.goto(-400, -200)
walls.goto(300, -200)
walls.goto(300, -300)
walls.up()
walls.goto(350, -300)
walls.down()
walls.goto(350, 0)
walls.goto(-320, 0)
walls.goto(-320, 200)
walls.goto(-400,200)
walls.hideturtle()
wallLefty1 = [200, -200] # Defines wall where you can't go past left
wallLefty2 = [-200, -300]
wallLeftx = [-400, 300]
wallRighty1 = [200,0] # Wall where you can't go past right
wallRighty2 = [0,-300]
wallRightx = [-320,350]
wallTopx1 = [-400,-320] #Wall where you can't go above
wallTopx2 = [-320,350]
wallTopy = [200,0]
wallBottomx1 = [-400] # Wall where you can't go bellow
wallBottomx2 = [300]
wallBottomy = [-200]
evilx1 = 150 # Variables for evil block
evily1 = -10
evilsquare1 = True #Defines where it moves
layer1 = Turtle()#Makes another layer for the user
layer1.speed(0)
layer1.hideturtle()
square(50,50)
x = -360
y = 160
up = False # Variables for deciding whether the user can move in a certain direction or not
down = False
left = False
right = False
layer1.clear() #Clears everything
while True:
if keyboard.is_pressed('w'): #Checks what key the user presses
up = True
elif keyboard.is_pressed('s'):
down= True
if keyboard.is_pressed('a'):
left = True
elif keyboard.is_pressed('d'):
right = True
for i in range(len(wallLefty1)): # Checks if the user is in a wall to the left
if x == wallLeftx[i] and y <= wallLefty1[i] and y >= wallLefty2[i]:
left = False
break
for i in range(len(wallRighty1)): #Checks if the user is in a wall to the right
if x == wallRightx[i] and y <= wallRighty1[i] and y >= wallRighty2[i]:
right = False
break
for i in range(len(wallTopx1)): #Checks if the user is in a wall to the top
if y == wallTopy[i] and x >= wallTopx1[i] and x <= wallTopx2[i]:
up = False
break
if y == wallBottomy[0] and x >= wallBottomx1[0] and x <= wallBottomx2[0]: #Checks if the user is in a wall to the bottom
down = False
if up: # Goes in a certain direction depending on the wasd keys
y += 5
elif down:
y -= 5
if left:
x -= 5
elif right:
x += 5
layer1.clear()
square(x,y)
if evily1 <= -200: #Checks what direction the evil block should go in
evilsquare1 = False
elif evily1 >= 0:
evilsquare1 = True
if evilsquare1: # Makes the evil block move
evily1 -= 10
else:
evily1 += 10
square(evilx1, evily1)
if (x == evilx1+5 or x == evilx1 or x ==evilx1-5) and (y == evily1+5 or y == evily1 or y == evily1-5): #Checks if user is by the evil block
x = -360 #Resets variables
y = 160
up = False #Resets movement variables
down = False
left = False
right = False
time.sleep(0.01) # Small delay
if(y<-300): # If the user completes the maze, the user goes to the next level
walls.clear()
layer1.clear()
break
def level2():
def square(x,y): #Variable to make blocks
layer1.up()
layer1.goto(x-5,y-5)
layer1.down()
layer1.goto(x+5,y-5)
layer1.goto(x+5,y+5)
layer1.goto(x-5,y+5)
layer1.goto(x-5,y-5)
walls = Turtle()
walls.up()
walls.speed(0)
#The walls
walls.goto(-400, 200)
walls.down()
walls.goto(-400, -200)
walls.goto(-100, -200)
walls.goto(-100, 0)
walls.goto(50,0)
walls.goto(50, -200)
walls.goto(350, -200)
walls.goto(350, -300)
walls.up()
walls.goto(400, -300)
walls.down()
walls.goto(400, 200)
walls.goto(0, 200)
walls.goto(0, 100)
walls.goto(-350, 100)
walls.goto(-350, 200)
walls.goto(-400,200)
walls.hideturtle()
#Defines where the user can pass and can't pass
wallLefty1 = [200, 200, 0, -200]
wallLefty2 = [-200, 100, -200, -300]
wallLeftx = [-400, 0, 50, 350]
wallRighty1 = [200, 0, 200]
wallRighty2 = [100, -200, -300]
wallRightx = [-350, -100, 400]
wallTopx1 = [-400, -350, 0]
wallTopx2 = [-350, 0, 400]
wallTopy = [200, 100, 200]
wallBottomx1 = [-400, -100, 50]
wallBottomx2 = [-100, 50, 350]
wallBottomy = [-200, 0, -200]
#Defines another layer for the block
layer1 = Turtle()
layer1.speed(0)
layer1.hideturtle()
square(50,50)
x = -360
y = 160
#Defines the evil squares
evilx1 = -400
evily1 = 50
evilsquare1 = True
evilx2 = -300
evily2 = 100
evilsquare2 = True
evilx3 = 200
evily3 = 200
evilsquare3 = True
#Variables for where user can move
up = False
down = False
left = False
right = False
layer1.clear()
while True:
#Checks what key the user presses
if keyboard.is_pressed('w'):
up = True
elif keyboard.is_pressed('s'):
down= True
if keyboard.is_pressed('a'):
left = True
elif keyboard.is_pressed('d'):
right = True
#Checks if the user is by a certain wall
for i in range(len(wallLefty1)):
if x == wallLeftx[i] and y <= wallLefty1[i] and y >= wallLefty2[i]:
left = False
break
for i in range(len(wallRighty1)):
if x == wallRightx[i] and y <= wallRighty1[i] and y >= wallRighty2[i]:
right = False
break
for i in range(len(wallTopx1)):
if y == wallTopy[i] and x >= wallTopx1[i] and x <= wallTopx2[i]:
up = False
break
for i in range(len(wallBottomy)):
if y == wallBottomy[i] and x >= wallBottomx1[i] and x <= wallBottomx2[i]:
down = False
break
#Moves the block
if up:
y += 5
elif down:
y -= 5
if left:
x -= 5
elif right:
x += 5
#Draws the sqyare
layer1.clear()
square(x,y)
#Checks how the evil squares move
if evilx1 >= 400:
evilsquare1 = False
elif evilx1 <= -400:
evilsquare1 = True
if evily2 <= -200:
evilsquare2 = False
elif evily2 >= 100:
evilsquare2 = True
if evily3 <= -200:
evilsquare3 = False
elif evily3 >= 200:
evilsquare3 = True
#Moves the evil squares
if evilsquare1:
evilx1 += 10
else:
evilx1 -= 10
if evilsquare2:
evily2 -= 10
else:
evily2 += 10
if evilsquare3:
evily3 -= 10
else:
evily3 += 10
#Draws the evil squares
square(evilx1, evily1)
square(evilx2, evily2)
square(evilx3, evily3)
#Checks if the user is around dan evil block, and if it is it resets the user's position
if (x == evilx1+5 or x == evilx1 or x ==evilx1-5) and (y == evily1+5 or y == evily1 or y == evily1-5):
x = -360
y = 160
if (x == evilx2+5 or x == evilx2 or x ==evilx2-5) and (y == evily2+5 or y == evily2 or y == evily2-5):
x = -360
y = 160
if (x == evilx3+5 or x == evilx3 or x == evilx3-5) and (y == evily3+5 or y == evily3 or y == evily3-5):
x = -360
y = 160
#Resets movement
up = False
down = False
left = False
right = False
time.sleep(0.01)
#If the user wins, the game ends
if y<-300:
break
#Runs level 1, then level 2 when level 1 is done, then prints you win the game when you finish all
level1()
level2()
print("You win the game!")