-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcompleted_game.py
More file actions
588 lines (498 loc) · 18.5 KB
/
completed_game.py
File metadata and controls
588 lines (498 loc) · 18.5 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
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
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
class Hero:
def __init__(self):
self.hp = 100
self.strength = 15
self.defense = 10
self.money = 100
self.weapon = None
def take_damage(self):
self.hp -= 20
if self.hp <= 0:
print("The dragon has defeated you")
else:
print(
f"The dragon attacks and inflicts 20 damage on you, your health is now {self.hp}")
def take_critical_damage(self):
self.hp -= 50
if self.hp <= 0:
print("The dragon has defeated you")
else:
print(
f"The dragon attacks and inflicts 50 damage on you, your health is now {self.hp}")
def take_damage_demon(self):
self.hp -= 35
if self.hp <= 0:
print("The demon has defeated you")
else:
print(
f"The demon attacks and inflicts 35 damage on you, your health is now {self.hp}")
def take_critical_damage_demon(self):
self.hp -= 70
if self.hp <= 0:
print("The demon has defeated you")
else:
print(
f"The demon attacks and inflicts 70 damage on you, your health is now {self.hp}")
inventory = []
def current_inventory(self):
print(f"Your current inventory is now {self.inventory}")
def spend_money(self, potion_type):
if potion_type == "Red":
self.money -= 20
print(f"You currently have {self.money} money")
self.inventory.append("Red Potion")
self.current_inventory()
elif potion_type == "Blue":
self.money -= 30
print(f"You currently have {self.money} money")
self.inventory.append("Blue Potion")
self.current_inventory()
elif potion_type == "Green":
self.money -= 40
print(f"You currently have {self.money} money")
self.inventory.append("Green Potion")
self.current_inventory()
def use_item(self):
print("Here is your current inventory: ")
count = 1
for item in self.inventory:
print(f"{count} : {item}")
count += 1
choice = int(input("Will you use an item? (1)Yes (2)No > "))
if choice == 1:
self.potion_select()
else:
return
def potion_select(self):
item_to_use = int(input("What item will you use? > "))
if item_to_use <= 0 or item_to_use > len(self.inventory):
print("That item does not exist! Please select actual item!")
else:
for item in self.inventory:
item = item_to_use - 1
if self.inventory[item] == "Red Potion":
print("You used the red potion")
print("Your HP has increased by 20 points")
self.hp += 20
print(f"Your current HP is now: {self.hp}")
return self.inventory.pop(item)
elif self.inventory[item] == "Blue Potion":
print("You used the blue potion")
print("Your HP has increased by 40 points")
self.hp += 40
print(f"Your current HP is now: {self.hp}")
return self.inventory.pop(item)
elif self.inventory[item] == "Green Potion":
print("You used the green potion")
print("Your HP has increased by 60 points")
self.hp += 60
print(f"Your current HP is now: {self.hp}")
return self.inventory.pop(item)
class Demon:
def __init__(self):
self.hp = 100
self.strength = 20
self.defense = 15
def take_damage(self):
self.hp -= 25
if self.hp <= 0:
print("YOU DID IT!! YOU DEFEATED THE DEMON AND SAVED YOUR KINGDOM!!")
else:
print(
f"You inflicted 25 damage to the demon, its health is now {self.hp}")
class Dragon:
def __init__(self):
self.hp = 100
self.magic = 1000
def take_damage(self):
self.hp -= 25
print(
f"""You dealt 25 damage to the dragon, its health is now {self.hp}.""")
class Weapon:
weapons = ["shield", "sword", "staff"]
def player_weapon(self):
print("""
|`-._/\_.-`|
| || |
|___o()o___|
|__((<>))__|
\ o\/o /
\ || /
\ || /
'.||.'
``
/| ________________
O|===|* >________________>
\|
.||,
\.`',/
= ,. =
||
||
||
||
||
||
""")
print(
f"Your current stats are: {hero.strength} Strength, {hero.defense} Defense, {hero.hp} HP")
choice = 0
while choice != range(1, 4):
choice = int(input(
f"Please select your weapon (1){self.weapons[0]}, (2){self.weapons[1]}, (3){self.weapons[2]} > "))
if choice == 1:
print(f"\nYou have selected the {self.weapons[0]}")
shield.attributes()
hero.weapon = shield
return
elif choice == 2:
print(f"\nYou have selected the {self.weapons[1]}")
sword.attributes()
hero.weapon = sword
return
elif choice == 3:
print(f"\nYou have selected the {self.weapons[2]}")
staff.attributes()
hero.weapon = staff
return
else:
print("\nThat is not a choice!! Please try again")
def attack_handling(self):
if hero.weapon == shield:
return shield.attack()
elif hero.weapon == sword:
return sword.attack()
elif hero.weapon == staff:
return staff.attack()
def defense_handling(self):
if hero.weapon == shield:
return shield.defend()
elif hero.weapon == sword:
return sword.defend()
elif hero.weapon == staff:
return staff.defend()
class Shield(Hero):
def __init__(self):
self.durability = 100
super().__init__()
def attributes(self):
self.defense += 20
print(f"Your defense has increased by 20 and is now {self.defense}")
def attack(self):
self.damage = 8
self.durability -= 5
if self.durability <= 0:
self.constitution()
else:
print(
f"Your shield durability has decreased by 5 is now {self.durability}")
def defend(self):
self.durability -= 0
if self.durability <= 0:
self.constitution()
else:
print(
f"Your shield durability remains the same at {self.durability}")
def constitution(self):
print("Your shield has broken")
game_over()
class Sword(Hero):
def __init__(self):
self.durability = 70
self.damage = 18
super().__init__()
def attributes(self):
self.strength += 20
print(
f"Your strength has increased by 20 points, your strength is now {self.strength}")
def attack(self):
self.damage = 18
self.durability -= 1
if self.durability <= 0:
return self.constitution()
else:
print(
f"Your sword durability has decreased by 1 and is now {self.durability}")
def defend(self):
self.durability -= 2
if self.durability <= 0:
return self.constitution()
else:
print(
f"Your sword durability has decreased by 2 and is now {self.durability}")
def constitution(self):
print("Your sword has broken")
game_over()
class Staff(Hero):
def __init__(self):
self.durability = 85
self.damage = 12
super().__init__()
def attributes(self):
self.strength += 10
print(
f"Your strength has increased by 10 points, your strength is now {self.strength}")
self.defense += 5
print(
f"Your defense has increased by 5 points, your defense is now {self.defense}")
def attack(self):
self.damage = 12
self.durability -= 1
if self.durability <= 0:
return self.constitution()
else:
print(
f"Your staff durability has decreased by 1 and is now {self.durability}")
def defend(self):
self.durability -= 1
if self.durability <= 0:
return self.constitution()
else:
print(
f"Your staff durability has decreased by 5 and is now {self.durability}")
def constitution(self):
print("Your staff has broken")
game_over()
# Creating instances of characters and weapons for first part of the game
hero = Hero()
player_weapon = Weapon()
shield = Shield()
sword = Sword()
staff = Staff()
dragon = Dragon()
# End game sequence
def end_game():
exit(0)
# Game over sequence
def game_over():
print("Game Over!")
print("""
@@@@@@@ @@@@@@@
@@@@@@@ @@@@@@@@@@@@@@@ @@@@@@@
@@@@@@@@ @@@@@@@@@@@@@@@@@@@ @@@@@@@@
@@@@@ @@@@@@@@@@@@@@@@@@@@@ @@@@@
@@@@@ @@@@@@@@@@@@@@@@@@@@@@@ @@@@@
@@ @@@@@@@@@@@@@@@@@@@@@@@@@ @@
@@@@@@@ @@@@@@ @@@@@@
@@@@@@ @@@@ @@@@@
@@@@@@ @@@@ @@@@@
@@@@@@ @@@@@@ @@@@@
@@@@@@@@@@@ @@@@@@@@@@
@@@@@@@@@@ @@@@@@@@@
@@ @@@@@@@@@@@@@@@@@ @@
@@@@ @@@@ @ @ @ @ @@@@ @@@@
@@@@@ @@@ @ @ @ @ @@@ @@@@@
@@@@@ @@@@@@@@@@@@@ @@@@@
@@@@ @@@@@@@@@@@ @@@@
@@@@@ @@@@@@@ @@@@@
@@@@@@@ @@@@@@@
@@@@@ @@@@@""")
exit(0)
# Part 2 Sequence
def part_two():
demon = Demon()
print("\nYou have now reached part 2 of the game")
print("You now find yourself inside a mysterious dungeon")
print("""
_________________________________________________________
/ | -_ - _ - |
/ |_-_ - _ - _ - _ - - |
| _ - _-- |
|, |
| .-'````````'. '(` .-'```````'- . |
| .` | `. `)' .` | `. |
| / | () \ U / | () \ |
| | | ; | o T o | | ; | |
| | | ; | . | . | | ; | |
| | | ; | . | . | | ; | |
| | | ; | .|. | | ; | |
| | |____;_________| | | |____;_________| |
| | / __ ; - | ! | / `'() _ - | |
| | / __ () -| - | / __-- - | |
| | / __-- _ | _- _ - | / __--_ | |
|__|/__________________|___________|/__________________|__|
/ _ -
/ -_- _ - _- _--- -_- -_
""")
print("\nYou're suddenly attacked by a demon!!! What do you do?")
while hero.hp > 0 or demon.hp > 0:
choice = int(input(
"What will you do (1)Attack, (2)Defend, (3)Do Nothing (4)view inventory? > "))
if choice == 1:
demon.take_damage()
player_weapon.attack_handling()
if demon.hp <= 0:
print("\nCONGRATS!! YOU JUST BEAT THE PYTHON ADVENTURE GAME!!")
print(
"You now return to your kingdom, patiently waiting for the next call to action.")
end_game()
elif choice == 2:
hero.take_damage_demon()
player_weapon.defense_handling()
if hero.hp <= 0:
game_over()
elif choice == 3:
hero.take_critical_damage_demon()
if hero.hp <= 0:
game_over()
elif choice == 4:
hero.use_item()
else:
print("\nThat's not a choice!! Let's try again.")
end_game()
# The transition scene between part 1 and part 2 of the game
def transition_phase():
print("\nSomething seems off, you notice a weird aura in the sky")
print(""" ` : | | | |: || : ` : | |+|: | : : :| . ` .
` : | :| || |: : ` | | :| : | : |: | . :
.' ': || |: | ' ` || | : | |: : | . ` . :.
`' || | ' | * ` : | | :| |*| : : :|
* * ` | : : | . ` ' :| | :| . : : * :.||
.` | | | : .:| ` | || | : |: | | ||
' . + ` | : .: . '| | : :| : . |:| ||
. . ` *| || : ` | | :| | : |:| |
. . . || |.: * | || : : :|||
. . . * . . ` |||. + + '| ||| . ||`
. * . +:`|! . |||| :.||`
+ . ..!|* . | :`||+ |||`
. + : |||` .| :| | | |.| ||` .
* + ' + :|| |` :.+. || || | |:`|| `
. .||` . ..|| | |: '` `| | |` +
. +++ || !|!: ` :| |
+ . . | . `|||.: .|| . . `
' `|. . `:||| + ||' `
__ + * `' `'|. `:""")
choice = int(input("Do you follow it to the source? (1)Yes (2)No > "))
if choice == 1:
part_two()
elif choice == 2:
print("\nThe aura eventually envelops your kingdom and you disappear into darkness")
game_over()
else:
print("\nI'm assuming you meant to put yes, please proceed")
part_two()
# Potion Shop
def potion_shop():
print("You've now entered the potion shop")
print("""
( " )
( _ * WHAT KIND OF POTION WOULD YOU LIKE?
* ( / \ ___
" " _/ /
( * ) ___/ |
) " _ o)'-./__
* _ ) (_, . $$$
( ) __ __ 7_ $$$$
( : { _) '--- $
______'___//__\ ____,|
) ( \_/ _____\_
.' \ \------''.
|=' '=| | )
| | | . _/
\ (. ) , / /__I_____|
'._/_)_(\__.' (__,(__,_]
@---()_.'---@ """)
print(f"You currently have {hero.money} money")
choice = 0
while choice != range(1, 5):
choice = int(input(
"Please make selection (1)Red Potion - 20 money, (2)Blue Potion - 30 money, (3)Green Potion - 40 money, (4)Exit Shop > "))
if choice == 1:
if hero.money < 20:
print("You don't have enough money!")
else:
print("You have selected the red potion")
hero.spend_money("Red")
elif choice == 2:
if hero.money < 30:
print("You don't have enough money!")
else:
print("You have selected the blue potion")
hero.spend_money("Blue")
elif choice == 3:
if hero.money < 40:
print("You don't have enough money!")
else:
print("You have selected the green potion")
hero.spend_money("Green")
elif choice == 4:
print("Thank you come again!")
main_menu()
else:
print("Invalid choice please try again")
# Part 1 sequence
def start_game():
greeting()
last_chance = int(
input("This is your last chance to back out, will you proceed (1)Yes, (2)No > "))
if last_chance == 1:
player_weapon.player_weapon()
elif last_chance == 2:
print("You have taken the coward's way out! Goodbye!")
end_game()
else:
print("Those were your only two options")
main_menu()
print("\nYou look in sky and see a dragon approaching the castle!!")
while hero.hp > 0 or dragon.hp > 0:
choice = int(input(
"What will you do (1)Attack, (2)Defend, (3)Do Nothing (4)view inventory? > "))
if choice == 1:
dragon.take_damage()
player_weapon.attack_handling()
if dragon.hp == 0:
print("\nVictory is yours!")
transition_phase()
elif choice == 2:
hero.take_damage()
player_weapon.defense_handling()
if hero.hp <= 0:
game_over()
elif choice == 3:
hero.take_critical_damage()
if hero.hp <= 0:
game_over()
elif choice == 4:
hero.use_item()
else:
print("\nThat's not a choice!! Let's try again.")
# Greeting scene before part 1 sequence
def greeting():
message = """WELCOME TO THE PYTHON ADVENTURE GAME!!
^ /\ /\ ~!~
^ (()) (())
^ /(())\ /(())\ ~!~
(((()))) (((())))
|^|^^|^|_______|^|^^|^|
| |^^^^|-_-_-_-_-|^^^^| |
(()) | "" |+_+_+_+_+| "" | (())
((())) | |[X]_+_[X]| | ((()))
(((())))| |+_+_+_+_+| |(((())))
|^|^^|^||____|-_-_-_-_-|____||^|^^|^|
|^^^^|_-_-_-_-_-_-_-_-_-_-_-_|^^^^|
~^~~| "" |_-_-_-_-_-_-_-_-_-_-_-_| "" |~~
~~ | |_+_+_+_+_+_+_+_+_+_+_+_| | ~^~
~^^| |_+[X]+_[X]_+_[X]_+[X]+_| |~~^
| |_+_+_+_+_+/l\+_+_+_+_+_| |
| |_-_-_-_-_|:::|_-_-_-_-_| |
|____|_+_+_+_+_|:::|_+_+_+_+_|____|"""
print(message)
# Main menu
def main_menu():
message = "PYTHON ADVENTURE GAME \nMain Menu\n"
print(message)
print("Once you start the game there is no going back! If you need potions now is the time to buy them!\n")
choice = int(input(
"Choose your path brave hero (1)Start Game, (2)Potion Shop, (3)Quit Game > "))
if choice == 1:
start_game()
elif choice == 2:
potion_shop()
elif choice == 3:
print("Why are you leaving?? Your adventure hasn't even started yet!!")
end_game()
else:
print("Since you can't follow directions, you're being thrown into the game!")
start_game()
# Invokes main menu function to start the game
main_menu()