-
Notifications
You must be signed in to change notification settings - Fork 1
/
doors.py
461 lines (410 loc) · 20.6 KB
/
doors.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
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
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
import random
import math
import os
import turtle
history = []
def intput(inpt): # Input sanitisation for integers
while True:
var = True
try:
res = int(input(inpt))
except ValueError:
print("Invalid input, please enter an integer!")
var = False
if var:
return res
def strinput(inpt): # input sanitisation for strings
while True:
var = True
try:
res = str(input(inpt))
except ValueError:
print("Invalid input, please enter valid hexadecimal!!")
var = False
if var:
return res
class Door: # door class, generates random stats when created
def __init__(self, doornum):
self.doornum = doornum
self.enemydif = random.randint(1, 100)
self.enemysize = random.randint(1, 100)
self.lootamount = random.randint(1, 100)
self.lootquality = random.randint(1, 100)
self.doordesc = classify(self)
def clear():
os.system('cls' if os.name == 'nt' else 'clear') # function to wipe the screen
def classify(d): # The heart of this program, gives a description to the randomly generated doors based purely on their stats. I may have spent too much time coming up with these words...
if d.enemydif + d.enemysize + d.lootamount + d.lootquality > 390:
opinion = random.choice(
["breathtaking", "incredible", "phenomenal", "mind-blowing", "absurd", "spectacular", "mind-boggling",
"supreme", "awe-inspiring", "extraordinary"])
elif d.enemydif + d.enemysize + d.lootamount + d.lootquality > 350:
opinion = random.choice(
["fantastic", "astonishing", "dazzling", "tremendous", "stunning", "marvellous", "magnificent",
"remarkable", "wonderful", "impressive"])
elif d.enemydif + d.enemysize + d.lootamount + d.lootquality > 300:
opinion = random.choice(
["great", "exceptional", "special", "grand", "majestic", "beautiful", "glorious", "brilliant", "spiffing",
"splendid"])
elif d.enemydif + d.enemysize + d.lootamount + d.lootquality > 200:
opinion = random.choice(
["fine", "quaint", "admirable", "acceptable", "robust", "satisfactory", "pleasing", "comely", "pretty"])
elif d.enemydif + d.enemysize + d.lootamount + d.lootquality > 150:
opinion = random.choice(
["tolerable", "uninspired", "respectable", "passable", "adequate", "goodish", "unexceptional",
"run-of-the-mill", "bog-standard", "cromulent"])
elif d.enemydif + d.enemysize + d.lootamount + d.lootquality > 100:
opinion = random.choice(
["mediocre", "inferior", "amateurish", "inane", "vacuous", "lesser", "lowly", "second-rate", "faulty",
"unsound"])
elif d.enemydif + d.enemysize + d.lootamount + d.lootquality > 50:
opinion = random.choice(
["crummy", "malformed", "bad", "poor", "dreadful", "lousy", "disagreeable", "dire", "unpleasant", "awful"])
else:
opinion = random.choice(
["abhorrent", "godawful", "deplorable", "barbaric", "wretched", "appalling", "ghastly", "grisly",
"cataclysmic", "abysmal"])
if d.enemysize > 90 or d.lootamount > 90:
size = random.choice(
['titanic', "colossal", "gargantuan", "immense", "stupendous", "enormous", "astronomical", "cosmic",
"Herculean", "ginormous"]) # door size huge
elif d.enemysize > 75 or d.lootamount > 75:
size = random.choice(
["giant", "vast", "substantial", "huge", "massive", "immense", "towering", "monumental", "mighty",
"towering"]) # door size large
elif d.enemysize > 50 or d.lootamount > 50:
size = random.choice(["midsize", "average", "medium", "moderate", "regular"]) # door size average
elif d.enemysize > 25 or d.lootamount > 25:
size = random.choice(["little", "small", "short", "cramped", "compact", "squat"]) # door size small
else:
size = random.choice(["miniature", "measly", "tiny", "minuscule", "puny", "pathetic"]) # door size tiny
if d.enemydif > 90 or (d.enemydif > 70 and d.lootquality < 40 and d.lootamount < 40) or (
d.enemysize < 20 and d.lootquality > 75): # door should be heavy/thick if it has a very dangerous creature (with or without loot), if it has a dangerous creature without loot, or if it has a weak creature with high quality loot
shape = random.choice(["heavy", "thick", "hulking", "dense", "bulky"])
elif (d.enemydif < 20 and d.enemysize > 70) or ((d.lootamount + d.lootquality) > 150 and (
d.enemydif + d.enemysize) < 50): # the door for lots of little enemies or one big friendly one should be thin/light, and if it is a room with lots of loot and almost no enemies it should also be thin
shape = random.choice(["paper-thin", "slight", "fine", "papery", "slender", "gossamer", "sheer"])
else: # average-shaped door
shape = random.choice(["average-thickness", "scraggy", "slim", "classic"])
if d.lootquality < 25: # in order for doors to be in good condition with low loot quality, they need to have a high enemysize with a low enemydif
if d.enemysize - d.enemydif > 50:
condition = random.choice(
["pristine", "factory-new", "immaculate", "sterile", "spotless", "untouched", "unadulterated",
"stainless", "flawless", "unsullied", "clean"]) # good condition
else:
condition = random.choice(
["beat-up", "mangled", "dismal", "shabby", "busted", "broken", "dilapidated", "rough", "seedy",
"shredded", "crude", "fragmented"]) # bad condition
elif d.lootquality < 75: # about average loot quality, so it will be good unless enemydif is greater than enemysize
if d.enemydif > d.enemysize:
condition = random.choice(
["beat-up", "mangled", "dismal", "shabby", "busted", "broken", "dilapidated", "rough", "seedy",
"shredded", "crude", "fragmented"]) # bad condition
else:
condition = random.choice(
["pristine", "factory-new", "immaculate", "sterile", "spotless", "untouched", "unadulterated",
"stainless", "flawless", "unsullied", "clean"]) # good condition
else: # this is pretty high quality loot, so will be good condition unless there is some monster issue in there
if d.enemydif + d.enemysize > 150:
condition = random.choice(
["beat-up", "mangled", "dismal", "shabby", "busted", "broken", "dilapidated", "rough", "seedy",
"shredded", "crude", "fragmented"]) # bad condition
else:
condition = random.choice(
["pristine", "factory-new", "immaculate", "sterile", "spotless", "untouched", "unadulterated",
"stainless", "flawless", "unsullied", "clean"]) # good condition
# large enemysize, high lootamount + low lootquality, very high enemydif + (low lootquality/lootamount) - all of these lead to high age.
if d.enemysize + d.enemydif > 150 and d.lootquality < 40 and d.lootamount > d.lootquality: # The perfect storm for a very, very old door
age = str(random.randint(1000, 2000)) + " year-old" # 1k<door<2k years
elif d.lootquality + d.lootamount < 75: # worthless room, could be a wide range of ages
age = str(random.randint(1, 1500)) + " year-old" # 1<door<1.5k years
elif d.enemysize < 40 and (d.enemydif - d.lootquality) > 50: # very dangerous, small creature, or just loot-poor
age = str(random.randint(750, 1250)) + " year-old" # 750<door<1.25k years
elif d.lootquality + d.lootamount > 125 > d.enemysize + d.enemydif: # near-unguarded room with great loot? must be very young
age = str(random.randint(1, 10)) + " year-old" # 1<door<10 years
else: # could be anything... but it will be a bit old
age = str(random.randint(500, 1750)) + " year-old" # 500<door<1.75k
# now for the door materials. These will all be determined by the stat hierarchies.
if d.enemysize < d.enemydif < d.lootquality < d.lootamount:
material = "sandstone"
elif d.enemysize < d.enemydif < d.lootamount < d.lootquality:
material = "ruby"
elif d.enemysize < d.lootquality < d.enemydif < d.lootamount:
material = "lead"
elif d.enemysize < d.lootquality < d.lootamount < d.enemydif:
material = "uranium"
elif d.enemysize < d.lootamount < d.enemydif < d.lootquality:
material = "mercury"
elif d.enemysize < d.lootamount < d.lootquality < d.enemydif:
material = "plutonium"
elif d.enemydif < d.enemysize < d.lootquality < d.lootamount:
material = "glass"
elif d.enemydif < d.enemysize < d.lootamount < d.lootquality:
material = "crystal"
elif d.enemydif < d.lootquality < d.enemysize < d.lootamount:
material = "plastic"
elif d.enemydif < d.lootquality < d.lootamount < d.enemysize:
material = "brick"
elif d.enemydif < d.lootamount < d.enemysize < d.lootquality:
material = "diamond"
elif d.enemydif < d.lootamount < d.lootquality < d.enemysize:
material = "gold"
elif d.lootquality < d.enemysize < d.enemydif < d.lootamount:
material = "coal"
elif d.lootquality < d.enemysize < d.lootamount < d.enemydif:
material = "arsenic"
elif d.lootquality < d.enemydif < d.enemysize < d.lootamount:
material = "stone"
elif d.lootquality < d.enemydif < d.lootamount < d.enemysize:
material = "wooden"
elif d.lootquality < d.lootamount < d.enemysize < d.enemydif:
material = "foam"
elif d.lootquality < d.lootamount < d.enemydif < d.enemysize:
material = "perspex"
elif d.lootamount < d.enemysize < d.enemydif < d.lootquality:
material = "platinum"
elif d.lootamount < d.enemysize < d.lootquality < d.enemydif:
material = "radium"
elif d.lootamount < d.enemydif < d.enemysize < d.lootquality:
material = "silver"
elif d.lootamount < d.enemydif < d.lootquality < d.enemysize:
material = "osmium"
elif d.lootamount < d.lootquality < d.enemysize < d.enemydif:
material = "cloth"
else:
material = "tungsten"
desctext = opinion + " " + size + " " + shape + " " + condition + " " + age + " " + material + " " + "door"
return desctext
def generatemaths(size, dif, livesleft):
lives = livesleft
if dif == 1: # cases for various enemy difficulty levels
for i in range(size): # addition
num1 = random.randint(0, 100)
num2 = random.randint(0, 100)
sol = int(num1 + num2)
if int(intput("What is " + str(num1) + " + " + str(num2) + "? ")) == int(sol):
print("Correct!\n")
else:
print("Wrong! The correct answer was " + str(sol) + "\n")
lives = lives - 1
print("You now have "+str(lives)+" lives left.\n")
elif dif == 2:
for i in range(size): # multiplication
num1 = random.randint(0, 11)
num2 = random.randint(0, 13)
sol = int(num1 * num2)
if int(intput("What is " + str(num1) + " * " + str(num2) + "? ")) == int(sol):
print("Correct!\n")
else:
print("Wrong! The correct answer was " + str(sol) + "\n")
lives = lives - 1
print("You now have " + str(lives) + " lives left.\n")
elif dif == 3:
for i in range(size): # division
num1 = random.randint(1, 30)
num2 = random.randint(1, 10)
while num1 % num2 != 0:
num1 = random.randint(1, 30)
num2 = random.randint(1, 10)
sol = int(num1 / num2)
if int(intput("What is " + str(num1) + " / " + str(num2) + "? ")) == int(sol):
print("Correct!\n")
else:
print("Wrong! The correct answer was " + str(sol) + "\n")
lives = lives - 1
print("You have " + str(lives) + " lives left.\n")
elif dif == 4:
for i in range(size): # Greatest common denominator
num1 = random.randint(1, 100)
num2 = random.randint(1, 100)
sol = math.gcd(num1, num2)
if int(intput(
"What is the greatest common denominator of " + str(num1) + " and " + str(num2) + "? ")) == int(
sol):
print("Correct!\n")
else:
print("Wrong! The correct answer was " + str(sol) + "\n")
lives = lives - 1
print("You now have " + str(lives) + " lives left.\n")
elif dif == 5:
for i in range(size): # find the discriminant
num1 = random.randint(-100, 100)
num2 = random.randint(-30, 30)
num3 = random.randint(-10, 10)
sol = int((num2 * num2) - (4 * num1 * num3))
if int(intput("What is the discriminant of " + str(num1) + "x^2 + " + str(num2) + "x + " + str(
num3) + "? ")) == int(sol):
print("Correct!\n")
else:
print("Wrong! The correct answer was " + str(sol) + "\n")
lives = lives - 1
print("You now have " + str(lives) + " lives left.\n")
elif dif == 6:
for i in range(size): # hard multiplication
num1 = random.randint(-25, 25)
num2 = random.randint(-125, 125)
sol = int(num1 * num2)
if int(intput("What is " + str(num1) + " * " + str(num2) + "? ")) == int(sol):
print("Correct!\n")
else:
print("Wrong! The correct answer was " + str(sol) + "\n")
lives = lives - 1
print("You now have " + str(lives) + " lives left.\n")
elif dif == 7:
for i in range(size): # hard division
num1 = random.randint(1, 1000)
num2 = random.randint(11, 11)
while num1 % num2 != 0:
num1 = random.randint(1, 1000)
num2 = random.randint(1, 11)
sol = int(num1 / num2)
if int(intput("What is " + str(num1) + " / " + str(num2) + "? ")) == int(sol):
print("Correct!\n")
else:
print("Wrong! The correct answer was " + str(sol) + "\n")
lives = lives - 1
print("You now have " + str(lives) + " lives left.\n")
elif dif == 8:
for i in range(size): # indices
num1 = random.randint(1, 9)
num2 = random.randint(0, 4)
sol = int(num1 ** num2)
if int(intput("What is " + str(num1) + " to the power of " + str(num2) + "? ")) == int(sol):
print("Correct!\n")
else:
print("Wrong! The correct answer was " + str(sol) + "\n")
lives = lives - 1
print("You now have " + str(lives) + " lives left.\n")
elif dif == 9:
for i in range(size): # binary conversion
num1 = random.randint(0, 1024)
sol = format(num1, 'b')
if int(intput("What is " + str(num1) + " written in binary?\n0b")) == sol:
print("Correct!\n")
else:
print("Wrong! The correct answer was " + str(sol) + "\n")
lives = lives - 1
print("You now have " + str(lives) + " lives left.\n")
else:
for i in range(size): # hexadecimal conversion
num1 = random.randint(0, 255)
sol = format(num1, 'x')
if str(strinput("What is " + str(num1) + " written in hexadecimal?\n0x")).lower() == str(sol).lower():
print("Correct!\n")
else:
print("Wrong! The correct answer was " + str(sol) + "\n")
lives = lives - 1
print("You now have " + str(lives) + " lives left.\n")
clear() #F
return lives
def generatedoors(): # create three new doors for the player to choose from
currentdoors = [Door(0), Door(1), Door(2)]
return currentdoors
def generateloot(amount, qual, mod, lives): # generate some loot after the battle
clear()
print("Now lets take a look at that loot...")
choicedict = {0: "Power!", 1: "Knowledge!", 2: "Sight!", 3: "Luck!"}
for i in range(math.floor(amount)):
modchoice = random.randrange(5)
if modchoice == 4 and lives <= 10 - math.floor(qual / 10):
lives += (math.floor(qual / 10) + 1)
print("You healed " + str((math.floor(qual / 10) + 1)) + " lives!")
else:
if modchoice == 4:
modchoice = random.randrange(4)
mod[modchoice] += (math.floor(qual/5) + 1)
print("You gained " + str((math.floor(qual/5) + 1)) + " " + choicedict[modchoice])
for i in range(len(mod)):
if mod[i] >= 90:
mod[i] = 90
print("\n")
print("You now have "+str(lives)+" lives, "+str(mod[0])+" power, "+str(mod[1])+" knowledge, "+str(mod[0])+" sight, and "+str(mod[0])+" luck.")
return [mod, lives]
def endgame(his): # end the game and draw out the map
history =his
turtle.speed(20)
turtle.pd()
clear()
print(history)
print("You have died!")
for i in history:
if i == 1:
turtle.seth(135)
turtle.forward(20)
turtle.back(20)
turtle.seth(90)
turtle.forward(12)
turtle.back(12)
turtle.seth(45)
turtle.forward(20)
elif i == 2:
turtle.seth(135)
turtle.forward(20)
turtle.back(20)
turtle.seth(45)
turtle.forward(20)
turtle.back(20)
turtle.seth(90)
turtle.forward(12)
else:
turtle.seth(45)
turtle.forward(20)
turtle.back(20)
turtle.seth(90)
turtle.forward(12)
turtle.back(12)
turtle.seth(135)
turtle.forward(20)
def rundoor(doorindex, modifiers, livesleft,currentdoors,his): # run the door
global history
clear()
lives = livesleft
results = []
ltamnt = currentdoors[doorindex].lootamount
ltqual = currentdoors[doorindex].lootquality
edif = currentdoors[doorindex].enemydif
esize = currentdoors[doorindex].enemysize
if esize - modifiers[0] < 0 or edif - modifiers[1] < 0:
print("This room appears to be free of any monsters...\n")
else:
lives = generatemaths(math.floor((esize - modifiers[0]) / 10) + 1, math.floor((edif - modifiers[1]) / 10) + 1,lives) #F
if lives <= 0:
endgame(his) #F
else:
return generateloot(math.floor((ltamnt + modifiers[2]) / 10) + 1, math.floor((ltqual + modifiers[3]) / 10), modifiers, lives) #F
def mainfunction():
# init: print title, print description, clear, first door, proceed to main gameplay loop
print("Welcome to Three Doors, a game by Felix Montanari - 2021")
print("In this game, you will be continually given the choice to enter one of three randomly generated doors, each with different amounts of enemies and loot. Luckily, you have very good eyes, and are able to come up with a great description of each of the doors, which will help guide your decision! The enemies in these rooms are the scariest of all, maths problems! So, make sure you choose wisely!")
input("Press ENTER to start!")
clear()
mods = [0, 0, 0, 0]
history = []
lives = 10
print("You have 10 lives.")
print("You enter the dungeon of tropical geometry, fearing that the rumours of its depth being infinite are true.")
#main loop
while True:
doors = generatedoors()
print("\n")
print("You notice that at the back of the room, there are three doors, each beckoning you in a different way...\nDespite this, you may only choose one, so which will it be?")
print("Will you choose the first door, the "+doors[0].doordesc+"?")
print("Or will you enter the second door, the "+doors[1].doordesc+"?")
print("Or perhaps the third door, the "+doors[2].doordesc+"?")
print("Please enter 1, 2, or 3. Prepare for the worst... Or the best!")
chce=int(intput("Choice: "))
while chce not in [1,2,3]:
print("That is not a door, please enter 1, 2 or 3.")
chce=int(intput("Choice: "))
result = rundoor(chce-1,mods,lives,doors,history) #F
history.append(chce)
try: # necessary as these things no longer work after game is ended.
mods = result[0]
lives = result[1]
for i in doors:
del i
except:
print("Thanks for playing!")
return
if __name__ == '__main__': # run the main functon
mainfunction() #F