-
Notifications
You must be signed in to change notification settings - Fork 0
/
adventureGameDefenseTest.py
1586 lines (1503 loc) · 67.6 KB
/
adventureGameDefenseTest.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
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
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
Functions in python console, but not virtural environments like pythonanywhere
Notes: Requires the installation of the dill module for save/load feature
To do:
Expand enemy selection [x]
Expand upon enemy damage in combat [x]
Add enemy defense modifier [x]
Make explored player class variable set explore counter to minimum of 3 so return to areas dont require exploration [x] done. Needs testing
Enemies slain/enemies remaining not functioning [x]
Add merchants to story areas. [x]
Add branching sidequest to obtain tears of denial/super weapons [x]
Boss health doesn't reset upon death [x] Fixed, but needs testing. Updated, needs further testing
Progress variables in Player class do not reset upon death, need to reinitialize upon death and start new game (i.e. hasGold) [x] fixed needs tested
Incorporate 'return to' area functions which allows for open world [x]
Incorporate merchants to purchase items from [x]
Implement in-game menu [x]
Build world by defining location functions to drive story, combat, and NPCs [x]
Buid save/load system [x]
Stress test inventory system and prevent items which do not need to be used from being used []
Incorporate Tears of Denial's auto revive [x]
Assignment of class respective legendary weapons from side quest [x]
add effects to weapons [x]
Write story [x]
Modifications:
Didn't track modifications prior to 6/12/20 as I was building the underlying system on the side to see if I could
06/12/20:
Added 'boss' parameter to Enemy class: Boolean True or False
Now cannot flee from bosses
merchant() functionality added
Fixed bug where enemy health doesn't reset on player death
Added to greatPlains() portion of story
Added in-game item menu feature
06/14/20:
Enemy health further modified to regenerate upon death
set variables to reset at new game
Added in game stat display, which displays more than the level up message for stats
Added keep ruins story segment and boss fight
Added 'has visited' boolean variables to player class, need to add corresponding functions
Added sidequest areas primordial oak tree and ancient lake
Added sidequest npcs Mysterious woman and lady in the lake
Added channeling stone for tears of denail sidequest
Added 'explored'*area* variable to Player class. Sets exploreCounter to minimum of 3 if an area has been explored sufficiently
Created newGameVariables() which sets all progress Player class variables to default options
6/15/20:
Added goldFinderEnemy variable
Enemies now drop a random amount of gold upon defeating them
Added goldFinderBoss variable
Bosses now drop a random amount of gold upon defeating them
6/16/20:
Added sub class SuperWeapon(Weapon) and weapons to it. Super Weapons are now assigned to the Player based off of starting weapon and completion of side quest
6/18/20:
Began recoding lost progress for weapon effects, balancing, removing gold from training dummy enemy and enemies slain count. Ruined Capitol story portion.
Added fortressThreshold area
6/19/20:
Necromancer fight fix
Undead dragon fight fix
Wrote fortress threshold story segment
Wrote kings fortress story segment
wrote throne room story segment
Updated display equipment option
Added more enemy types and increased encounter rates
Added defense parameter to Enemy and Player class objects
Incorporated defense modifier into combat
Balanced weapons
6/22/20:
Updated menu functions for quit and return to ask if sure
directory: cd /C/Users/Alsty/Desktop/Classes/CSCI_23000/adventureGame
git push: git push -u https://github.com/alistenberger/adventureGame.git
Professor Harris video (https://www.youtube.com/watch?v=e9miazksRD0)
Requires Dill:
$ pip install dill or 'pip3.7 install --user dill' in python anywhere bash console. Depending on your version of python.user.name
This project won't function in virtural environment, however works in Python console.
dill documentation here:
https://pypi.org/project/dill/
https://dill.readthedocs.io/en/latest/index.html
dill citation:
M.M. McKerns, L. Strand, T. Sullivan, A. Fang, M.A.G. Aivazis,
"Building a framework for predictive science", Proceedings of
the 10th Python in Science Conference, 2011;
http://arxiv.org/pdf/1202.1056
Michael McKerns and Michael Aivazis,
"pathos: a framework for heterogeneous computing", 2010- ;
http://trac.mystic.cacr.caltech.edu/project/pathos
"""
from random import *
import pickle
import dill
import pdb
name = ""
level = 1
strength = 10
defense = 10
maxHealth = 100
health = 100
weaponEquip = ""
gold = 100
inventory = []
exp = 0
progressCode = "a000"
def setName():
global name
user.name = input("""Late one fine Summer evening, after supervising your peasants toiling in the mudfields all day, you find that you have a lingering feeling that a quest is on the horizon. "Just my luck" you think to yourself.
"Another group of travelers whom will most certainly fail to remember my name which is: " Please enter your name: """)
name = user.name
return user.name
name
def cheatMenu():
keepGoingCheat = True
while keepGoingCheat:
print("Enter your cheat. Or enter 'options' to return to options menu. ")
cheatInput = input("> ")
if cheatInput == "IDDQD":
user.maxHealth = 9999
user.health = 9999
print("Your health is now 9999")
elif cheatInput == "dnstuff":
user.inventory.append(healthPotionLarge)
user.inventory.append(healthPotionLarge)
user.inventory.append(healthPotionLarge)
user.weaponEquip = user.weaponEquip.upgrade
print("Got stuff")
elif cheatInput.lower() == "options":
keepGoingCheat = False
optionsMenu()
else:
print("Nice try cheater...")
def difficultyChoice():
keepGoing = True
while keepGoing:
print("""Please select a difficulty:
0. Easy
1. Medium
2. Hard
3. Please hurt my feelings""")
difficultyChoice = input("> ")
global gameDifficulty
if difficultyChoice == "0":
gameDifficulty = "easy"
keepGoing = False
elif difficultyChoice == "1":
gameDifficulty = "medium"
keepGoing = False
elif difficultyChoice == "2":
gameDifficulty = "hard"
keepGoing = False
elif difficultyChoice == "3":
print("Are you sure? Type 'yes or 'no'")
yesno = input("> ")
if yesno.lower() == "yes":
gameDifficulty = "extreme"
print("Now you've done it. Your adventure is cursed.")
keepGoing = False
else:
print("Good choice.")
else:
print("I didn't quite understand that.")
return gameDifficulty
gameDifficulty = "normal"
def chooseCharClass():
print("""Which best describes you?
0. A knight, proud and strong. You like to solve problems head on and through brute force.
1. An assassain, the dark is your ally. You like to solve problems behind the scenes.
2. A renegade, quick-footed and elusive. You like to solve problems carefully.
3. A sorcerer, acquired knowledge and wisdom through a great deal of time. You like to solve problems with your superior intellect.""")
charClass = input("> ")
return charClass
def setCharClass(charClass):
global weaponEquip
if charClass == "0":
user.weaponEquip = sword
weaponEquip = user.weaponEquip
user.weaponEquip.strength = 10
user.defense = 10
elif charClass == "1":
user.weaponEquip = dagger
weaponEquip = user.weaponEquip
user.weaponEquip.strength = 5
user.defense = 7
elif charClass == "2":
user.weaponEquip = bow
weaponEquip = user.weaponEquip
user.weaponEquip.strength = 7
user.defense = 5
elif charClass == "3":
user.weaponEquip = staff
weaponEquip = user.weaponEquip
user.weaponEquip.strength = 8
user.defense = 6
return user.weaponEquip
weaponEquip
def setProgressCode(code):
user.progressCode = code
return user.progressCode
def getProgressCode(self):
progressCode = user.progressCode
return progressCode
def setLocation(progressCode):
if progressCode == "a000":
startHouse()
elif progressCode == "a001":
southernSettlement()
elif progressCode == "a002":
greatPlains()
elif progressCode == "a003":
keepRuins()
elif progressCode == "a004":
ruinedCapitol()
elif progressCode == "a005":
primordialOakTree()
elif progressCode == "a006":
ancientLake()
elif progressCode == "a010":
fortressThreshold()
elif progressCode == "a020":
kingsFortress()
elif progressCode == "a030":
throneRoom()
def newGameVariables():
user.hasGold = False
user.hasTearsOfDenial = False
user.startHouseVisited = False
user.southernSettlementVisited = False
user.greatPlainsVisited = False
user.exploredGreatPlains = False
user.primordialOakTreeVisited = False
user.keepRuinsVisited = False
user.exploredKeepRuins = False
user.hasChannelingStone = False
user.brokeThroughWall = False
user.ancientLakeVisited = False
user.worthinessProven = False
user.acceptedLakeGift = False
user.ruinedCapitolVisited = False
user.exploredRuinedCapitol = False
user.greatPlainsBossDefeated = False
user.keepRuinsBossDefeated = False
user.ruinedCapitolBossDefeated = False
user.fortressThresholdExplored = False
user.fortressLeverPulled = False
user.throneRoomDiscovered = False
user.throneRoomBossDefeated = False
user.kingsFortressExplored = False
user.enemiesSlain = 0
def newGame(gameDifficulty):
global name
name = setName()
if gameDifficulty == "easy":
user.level = 1
user.strength = 20
user.defense = 10
user.maxHealth = 200
user.health = 200
user.weaponEquip = sword
user.gold = 500
user.inventory.append(healthPotionSmall)
user.exp = 0
elif gameDifficulty == "normal":
user.level = 1
user.strength = 10
user.defense = 10
user.maxHealth = 100
user.health = 100
user.weaponEquip = sword
user.gold = 100
user.inventory.append(healthPotionSmall)
user.exp = 0
elif gameDifficulty == "hard":
user.level = 1
user.strength = 7
user.defense = 7
user.maxHealth = 70
user.health = 70
user.weaponEquip = sword
user.gold = 70
user.exp = 0
elif gameDifficulty == "extreme":
user.level = 1
user.strength = 5
user.defense = 5
user.maxHealth = 50
user.health = 50
user.weaponEquip = sword
user.gold = 50
user.exp = 0
else:
user.level = 1
user.strength = 10
user.defense = 10
user.maxHealth = 100
user.health = 100
user.weaponEquip = sword
user.gold = 100
user.exp = 0
setProgressCode("a000")
charClass = chooseCharClass()
setCharClass(charClass)
newGameVariables()
setLocation(progressCode)
return name
return progressCode
class Weapon():
def __init__(self, name, stength, effect, cost, upgrade=""):
self.name = name
self.strength = strength
self.effect = effect
self.cost = cost
self.upgrade = upgrade
class SuperWeapon(Weapon):
def __init__(self, name, strength, effect, cost, description=""):
self.name = name
self.strength = strength
self.effect = effect
self.cost = cost
self.description = description
excalibur = SuperWeapon("Excalibur", 30, "adds random damage", 1000, "A sword of legend, once wielded by a great king. It is only passed to those deemed worthy of wielding it.")
dragonBoneDagger = SuperWeapon("Dragon Bone Dagger", 8, "attacks three times", 1000, "A dagger carved by an ancient hero from the bones of a dragon he once slew. It is only passed to those deemed worthy of wielding it.")
avelyn = SuperWeapon("Avelyn", 12, "attacks 3 times and take less damage when attacking", 1000, "A repeating crossbow once cherished by an ancient blacksmith. It is only passed to those deemed worthy of wielding it.")
izalithStaff = SuperWeapon("Izalith Staff", 16, "adds elemental damage", 1000, "A lost staff from an ancient civilization. It is only passed to those deemed worthy of wielding it.")
sword = Weapon("sword", 10, "Just a sword", 50, excalibur)
dagger = Weapon("dagger", 5, "Attack two times in a turn", 10, dragonBoneDagger)
bow = Weapon("bow and arrows", 7, "Take less damage when attacking", 50, avelyn)
staff = Weapon("magic staff", 8, "Apply elemental damage", 100, izalithStaff)
def optionsMenu():
keepGoingOptions = True
while keepGoingOptions:
print("""Welcome to the options menu, here you can enter cheats here. Please select an option.
1. Cheats
2. Main Menu""")
optionsChoice = input("> ")
if optionsChoice == "1":
keepGoingOptions = False
cheatMenu()
elif optionsChoice == "2":
keepGoingOptions = False
mainMenu()
else:
print("I'm sorry, I didn't understand that.")
def mainMenu():
keepGoingMain = True
while keepGoingMain:
print("""Welcome to the distant past, a grand adventure awaits you! What would you like to do? Input 0, 1, 2, or 3.
0. Begin a new journey
1. Load your previous adventure
2. Options
3. Quit""")
menuSelection = input("> ")
if menuSelection == "0":
keepGoingMain = False
difficultyChoice()
newGame(gameDifficulty)
elif menuSelection =="1":
keepGoingMain = False
loadGame()
print("Loading game")
elif menuSelection == "2":
keepGoingMain = False
optionsMenu()
elif menuSelection == "3":
keepGoingMain = False
quit()
else:
print("I do not understand, please make another selection")
class Player():
def __init__(self, name="", level=1, strength=10, defense=10, maxHealth=100, health=100, weaponEquip="", gold=100, inventory=[], exp=0, progressCode = "a000"):
self.name = name
self.level = level
self.strength = strength
self.defense = defense
self.maxHealth = maxHealth
self.health = health
self.weaponEquip = weaponEquip
self.gold = gold
self.inventory = inventory
self.exp = exp
self.progressCode = progressCode
def attack(self, enemy):
success = randint(0, 10)
maxDefenseMod = int(enemy.defense/2)
defenseModifier = int(randint(1, maxDefenseMod))
if user.weaponEquip == dagger:
damage = int((user.strength/2) + user.weaponEquip.strength) - defenseModifier
elif user.weaponEquip == dragonBoneDagger:
damage = int((user.strength/2) + user.weaponEquip.strength) - defenseModifier
elif user.weaponEquip == staff:
damage = int(user.weaponEquip.strength + user.strength + randint(1, 5)) - defenseModifier
elif user.weaponEquip == izalithStaff:
damage = int(user.weaponEquip.strength + user.strength + randint(10, 29)) - defenseModifier
elif user.weaponEquip == excalibur:
damage = int(user.weaponEquip.strength + user.strength + randint(1, 10)) - defenseModifier
else:
damage = int(user.weaponEquip.strength + user.strength) - defenseModifier
if success != 0:
print("You attacked the {} with your {} and did {} damage!".format(enemy.name, user.weaponEquip.name, damage))
enemy.health -= damage
print("The {} now has {} health left!".format(enemy.name, enemy.health))
else:
print("Your attack missed!")
def equipWeapon(self, weapon):
user.weaponEquip = weapon
return user.weaponEquip
def levelUp(self):
user.maxHealth += 20
user.strength += 3
user.level += 1
user.health = user.maxHealth
user.defense += 2
def getStats(self):
print("""
Your maximum health is: {}
Your strength is: {}
Your level is: {}""".format(user.maxHealth, user.strength, user.level))
enemiesSlain = 0
enemiesRemaining = 20
def getStatsMenu(self):
print("""
Here are your stats:
Name: {}
Level: {}
Strength: {}
Defense: {}
Max Health: {}
Current Health: {}
Amount of Gold: {}
Total Experience: {}
Total Enemies Slain: {}""".format(user.name, user.level, user.strength, user.defense, user.maxHealth, user.health, user.gold, user.exp, user.enemiesSlain))
def gainExp(self, enemy):
user.exp += enemy.expGiven
if user.level == 1:
if user.exp >= 10:
user.levelUp()
print("You leveled up! Your stats are now: ")
user.getStats()
else:
print("Great Job!")
elif user.level == 2:
if user.exp >= 25:
user.levelUp()
print("You leveled up! Your stats are now: ")
user.getStats()
else:
print("Great Job!")
elif user.level == 3:
if user.exp >= 50:
user.levelUp()
print("You leveled up! Your stats are now: ")
user.getStats()
else:
print("Great Job!")
elif user.level == 4:
if user.exp >= 85:
user.levelUp()
print("You leveled up! Your stats are now: ")
user.getStats()
else:
print("Great Job!")
elif user.level == 5:
if user.exp >= 120:
user.levelUp()
print("You leveled up! Your stats are now: ")
user.getStats()
else:
print("Great Job!")
elif user.level == 6:
if user.exp >= 150:
user.levelUp()
print("You leveled up! Your stats are now: ")
user.getStats()
else:
print("Great Job!")
elif user.level == 7:
if user.exp >= 200:
user.levelUp()
print("You leveled up! Your stats are now: ")
user.getStats()
else:
print("Great Job!")
elif user.level == 8:
if user.exp >= 250:
user.levelUp()
print("You leveled up! Your stats are now: ")
user.getStats()
else:
print("Great Job!")
elif user.level == 9:
if user.exp >= 300:
user.levelUp()
print("You leveled up! Your stats are now: ")
user.getStats()
else:
print("Great Job!")
elif user.level == 10:
if user.exp >= 350:
user.levelUp()
print("You leveled up! Your stats are now: ")
user.getStats()
else:
print("Great Job!")
else:
print("Great Job!")
def itemMenu(self):
keepGoing = True
while keepGoing:
print("Here are the items in your inventory: ")
for index in range(len(user.inventory)):
itemName = user.inventory[index].name
number = index
print("{}. {}".format(number, itemName))
userChoice = input("Please select an item or type 'quit' to escape. ")
if userChoice.isalpha() == True:
userChoice = str(userChoice)
if userChoice == "quit":
keepGoing = False
else:
print("I'm sorry, I didn't understand that.")
elif userChoice.isnumeric() == True:
userChoice = int(userChoice)
if userChoice in range(len(user.inventory)):
if user.health != user.maxHealth:
usePotion(user.inventory[userChoice])
user.inventory.pop(userChoice)
else:
print("You don't need to use that right now.")
else:
print("I'm sorry, I didn't understand that.")
else:
print("I'm sorry, I didn't understand that.")
hasGold = False
hasTearsOfDenial = False
startHouseVisited = False
southernSettlementVisited = False
greatPlainsVisited = False
exploredGreatPlains = False
primordialOakTreeVisited = False
keepRuinsVisited = False
exploredKeepRuins = False
hasChannelingStone = False
brokeThroughWall = False
ancientLakeVisited = False
worthinessProven = False
acceptedLakeGift = False
ruinedCapitolVisited = False
exploredRuinedCapitol = False
greatPlainsBossDefeated = False
keepRuinsBossDefeated = False
ruinedCapitolBossDefeated = False
fortressThresholdExplored = False
fortressLeverPulled = False
throneRoomDiscovered = False
throneRoomBossDefeated = False
user = Player(name, level, strength, defense, maxHealth, health, weaponEquip, gold, inventory, exp, progressCode)
def setLevel(self):
global level
level = user.level
return level
def setStrength(self):
global strength
strength = user.strength
return strength
def setMaxHealth(self):
global maxHealth
maxHealth = user.maxHealth
return maxHealth
def setGlobalHealth(self):
global health
health = user.health
return health
def setGlobalWeaponEquip(self):
global weaponEquip
weaponEquip = user.weaponEquip
return weaponEquip
def setGlobalGold(self):
global gold
gold = user.gold
return gold
def setGlobalInventory(self):
global inventory
inventory = user.inventory
return inventory
def setGlobalProgressCode(self):
global progressCode
progressCode = user.progressCode
return progressCode
class Enemy():
def __init__(self, name, strength, defense, maxHealth, health, expGiven, boss=False):
self.name = name
self.strength = strength
self.defense = defense
self.maxHealth = maxHealth
self.health = health
self.expGiven = expGiven
self.boss = boss
def attack(self, enemy):
success = randint(0, 10)
maxDefenseMod = int(user.defense/2)
defenseModifier = int(randint(1, maxDefenseMod))
if success != 0:
if user.weaponEquip == bow and enemy != trainingDummy:
damage = enemy.strength - randint(1, 5) - defenseModifier
if damage < 0:
damage = 0
elif user.weaponEquip == avelyn and enemy != trainingDummy:
damage = enemy.strength - randint(5, 10)- defenseModifier
if damage < 0:
damage = 0
else:
damage = enemy.strength - defenseModifier
if damage < 0:
damage = 0
print("The {} attacks you! You take {} damage!".format(enemy.name, damage))
user.health -= damage
print("Your health is now {}.".format(user.health))
else:
print("The {}'s attack missed".format(enemy.name))
trainingDummy = Enemy("training dummy", 0, 10, 100, 100, 0, False)
goblin = Enemy("goblin", 10, 5, 50, 50, 5, False)
mercenary = Enemy("mercenary", 12, 6, 60, 60, 5, False)
highwayman = Enemy("highwayman", 12, 6, 60, 60, 5, False)
goblinWarlord = Enemy("Goblin Warlord", 15, 8, 100, 100, 10, True)
troll = Enemy("troll", 25, 12, 125, 125, 13, False)
goblinWarrior = Enemy("goblin warrior", 20, 10, 125, 125, 12, False)
ghastlyTroll = Enemy("ghastly troll", 30, 15, 200, 200, 30, True)
wight = Enemy("wight", 20, 10, 150, 150, 15, False)
phantom = Enemy("phantom", 20, 10, 150, 150, 15, False)
undeadDragon = Enemy("Undead Dragon", 30, 15, 300, 300, 40, True)
undeadWarrior = Enemy("Undead Warrior", 25, 13, 200, 200, 20, False)
undeadKnight = Enemy("undead knight", 22, 11, 220, 220, 21, False)
undeadEliteGuard = Enemy("Undead Elite Guard", 25, 13, 250, 250, 23, False)
dragon = Enemy("dragon", 50, 20, 500, 500, 100, True)
class Item():
def __init__(self, name, effect, cost):
self.name = name
self.effect = effect
self.cost = cost
healthPotionSmall = Item("small health potion", 20, 10)
healthPotionMedium = Item("medium health potion", 50, 25)
healthPotionLarge = Item("large health potion", 100, 50)
tearsOfDenial = Item("tears of denial", 100, 500)
class npc():
def __init__(self, name, inventory):
self.name = name
self.inventory = inventory
settlementMerchant = npc("Settlement Merchant", healthPotionSmall)
wanderingMerchant = npc("Wandering Merchant", healthPotionMedium)
ghastlyMerchant = npc("Ghastly Merchant", healthPotionLarge)
hardyMerchant = npc("Hardy Merchant", healthPotionLarge)
mysteriousWoman = npc("Mysterious Woman", tearsOfDenial)
ladyInTheLake = npc("The Lady in the Lake", "null")
class Location():
def __init__(self, locationName, locationCode, enemy, npc, nextLocation):
self.locationName = locationName
self.locationCode = locationCode
self.enemy = enemy
self.npc = npc
self.nextLocation = nextLocation
throneRoom1 = Location("The king's throne room", "a030", "null", "null", "null")
kingsFortress1 = Location("The king's fortress", "a020", undeadEliteGuard, "null", throneRoom1)
fortressThreshold1 = Location("Fortress Threshold", "a010", undeadWarrior, "null", kingsFortress1)
ruinedCapitol1 = Location("The Ruined Capitol", "a004", wight, hardyMerchant, fortressThreshold1)
keepRuins1 = Location("Great Keep Ruins", "a003", troll, ghastlyMerchant, ruinedCapitol1)
ancientLake1 = Location("The Ancient Lake", "a006", "null", ladyInTheLake, keepRuins1)
greatPlains1 = Location("The Great Plains", "a002", goblin, wanderingMerchant, keepRuins1)
primordialOakTree1 = Location("The Primordial Oak Tree", "a005", "null", mysteriousWoman, greatPlains1)
southernSettlement1 = Location("Southern Settlement", "a001", trainingDummy, settlementMerchant, greatPlains1)
startHouse1 = Location("Your house in the Southern Settlement", "a000", trainingDummy, "null", southernSettlement1)
def usePotion(potion):
if user.health == user.maxHealth:
print("You do not need to use that right now, but you drink it anyway.")
else:
user.health += potion.effect
if user.health > user.maxHealth:
user.health = user.maxHealth
print("You drank the {}, your health is now {}/{}.".format(potion.name, user.health, user.maxHealth))
def battle(enemy):
print("You encounter a {}!".format(enemy.name))
userRoll = randint(1, 10)
enemyRoll = randint(1, 10)
goldFinderEnemy = randint(15, 50)
keepGoing = True
while keepGoing:
print("You have {} health remaining.".format(user.health))
print("""What would you like to do?
1. Attack
2. Item
3. Flee""")
choice = input("> ")
if choice == "1":
if userRoll >= enemyRoll:
if user.weaponEquip == avelyn or user.weaponEquip == dragonBoneDagger:
user.attack(enemy)
user.attack(enemy)
user.attack(enemy)
elif user.weaponEquip == dagger:
user.attack(enemy)
user.attack(enemy)
else:
user.attack(enemy)
if enemy.health <= 0:
print("The {} has been defeated. You gain strength.".format(enemy.name))
if enemy != trainingDummy:
print("Got {} gold!".format(goldFinderEnemy))
user.gold += goldFinderEnemy
user.enemiesSlain += 1
user.enemiesRemaining -= 1
user.gainExp(enemy)
enemy.health = enemy.maxHealth
keepGoing = False
else:
enemy.attack(enemy)
if user.health <= 0:
if user.hasTearsOfDenial == True:
user.health = user.maxHealth
print("The mysterious woman's vial breaks open as your body crashes to the ground, spilling the contents inside.")
input("Press enter to continue.")
print("You suddenly feel the life return to your body. Filled with the will to continue, you stand.")
user.hasTearsOfDenial = False
elif user.hasTearsOfDenial == False:
keepGoing = False
enemy.health = enemy.maxHealth
death()
else:
enemy.attack(enemy)
if user.health <= 0:
if user.hasTearsOfDenial == True:
user.health = user.maxHealth
print("The mysterious woman's vial breaks open as your body crashes to the ground, spilling the contents inside.")
input("Press enter to continue.")
print("You suddenly feel the life return to your body. Filled with the will to continue, you stand.")
user.hasTearsOfDenial = False
elif user.hasTearsOfDenial == False:
keepGoing = False
enemy.health = enemy.maxHealth
death()
if user.weaponEquip == avelyn or user.weaponEquip == dragonBoneDagger:
user.attack(enemy)
user.attack(enemy)
user.attack(enemy)
elif user.weaponEquip == dagger:
user.attack(enemy)
user.attack(enemy)
else:
user.attack(enemy)
if enemy.health <= 0:
print("The {} has been defeated. You gain strength.".format(enemy.name))
if enemy != trainingDummy:
print("Got {} gold!".format(goldFinderEnemy))
user.gold += goldFinderEnemy
user.enemiesSlain += 1
user.enemiesRemaining -= 1
user.gainExp(enemy)
enemy.health = enemy.maxHealth
keepGoing = False
elif choice == "2":
user.itemMenu()
elif choice == "3":
if enemy.boss == False:
fleeSuccess = randint(1, 4)
if fleeSuccess != 1:
keepGoing = False
print("You got away")
else:
print("The {} prevents your escape and calls you a chicken!".format(enemy.name))
enemy.attack(enemy)
elif enemy.boss == True:
print("You can't escape!")
else:
print("I didn't understand that, please try again")
def death():
print("Your body crashes to the floor and you feel your strength leave you.")
print("YOU DIED")
mainMenu()
def saveGame():
dill.dump_session(filename = "adventureGameSave.txt", main=None, byref=False)
def loadGame():
dill.load_session(filename = "adventureGameSave.txt", main=None)
setLocation(getProgressCode(user))
def explore():
exploreNum = randint(1, 10)
return exploreNum
def inGameMenu():
keepGoing = True
while keepGoing:
print("""What would you like to do?
0. Item Menu
1. Stats
2. Equipment
3. Save Game
4. Return to Game
5. Main Menu
6. Quit Game""")
inGameMenuInput = input("> ")
if inGameMenuInput == "0":
user.itemMenu()
elif inGameMenuInput == "1":
user.getStatsMenu()
elif inGameMenuInput == "2":
print("""Your weapon is: {}
Your weapon's strength is {}
Your weapon's effect is '{}'""".format(user.weaponEquip.name, user.weaponEquip.strength, user.weaponEquip.effect))
if user.hasChannelingStone == True:
print("You have the channeling stone.")
if user.hasTearsOfDenial == True:
print("You have the Tears of Denial")
elif inGameMenuInput == "3":
saveGame()
print("Saving your progress")
print("Progress saved")
elif inGameMenuInput == "4":
keepGoing = False
elif inGameMenuInput == "5":
keepGoingReturn = True
while keepGoingReturn:
print("""Are you sure you want to return to the menu? All unsaved progress will be lost.
0. Yes
1. No""")
returnInput = input("> ")
if returnInput == "0":
keepGoingReturn = False
keepGoing = False
mainMenu()
elif returnInput == "1":
keepGoingReturn = False
else:
print("I'm sorry, I didn't quite understand that.")
elif inGameMenuInput == "6":
keepGoingQuit = True
while keepGoingQuit:
print("""Are you sure you want to quit the game? All unsaved progress will be lost.
0. Yes
1. No""")
quitInput = input("> ")
if quitInput == "0":
keepGoingQuit = False
keepGoing = False
quit()
elif quitInput == "1":
keepGoingQuit = False
else:
print("I'm sorry, I didn't quite understand that.")
def merchant(area):
merchantName = area.npc.name
item = area.npc.inventory
itemName = area.npc.inventory.name
itemCost = area.npc.inventory.cost
keepGoingMerchant = True
while keepGoingMerchant:
print("You have {} gold.".format(user.gold))
print("""{}: What would you like to buy?
0. {} : {} gold
1. Exit the shop""".format(merchantName, itemName, itemCost))
merchantChoice = input("> ")
if merchantChoice == "0":
keepGoingPurchase = True
print("""That will cost {} gold. Purchase?
0. No
1. Yes""".format(itemCost))
purchaseChoice = input("> ")
if purchaseChoice == "0":
keepGoingPurchase = False
elif purchaseChoice == "1":
if user.gold >= itemCost:
user.gold -= itemCost
user.inventory.append(item)
print("Bought {}, you spent {} gold. Gold remaining: {}".format(itemName, itemCost, user.gold))
keepGoingPurchase = False
else:
print("You can't afford that.")
keepGoingPurchase = False
else:
print("I don't understand")
elif merchantChoice == "1":
print("{}: Goodbye".format(merchantName))
keepGoingMerchant = False
else:
print("I'm sorry, I didn't understand that.")
def startHouse():
setProgressCode("a000")
print("You awaken in your bed to the sound of horsehooves. Instinctively, you reach for your trusty {} and climb out of your bed.".format(user.weaponEquip.name))
print("You hurredly head towards the door, still dreary from a restless night of sleep you nearly forget your gold pouch.")
area = startHouse1
keepGoing1 = True
while keepGoing1:
print("""What do you want to do?
0. Head out the door
1. Get your gold from the drawer
2. Look around
3. Look out the window""")
userChoice1 = input("> ")
if userChoice1 == "0":
if user.hasGold == False:
print("I need to get my gold first!")
elif user.hasGold == True:
keepGoing1 = False
user.startHouseVisited = True
setProgressCode("a001")
southernSettlement()
elif userChoice1 == "1":
if user.hasGold == False:
print("You stumble over to your dresser and pick up your gold pouch.")
print("Got {} gold!".format(user.gold))
user.hasGold = True
else: print("You've already collected your gold, there's nothing left in the drawer!")
elif userChoice1 == "2":
print("You look around the unkempt room. 'Nothing but useless trinkets,' you think to yourself.")
elif userChoice1 == "3":
print("You look out the window, you can see a man dressed as a king speaking with the guards. It sounds like they're discussing the migration of coconuts")
elif userChoice1 == "4":
keepGoing1 = False
accessConsole()
else:
print("I'm sorry, I didn't quite understand. Try getting your gold.")
def southernSettlement():
setProgressCode("a001")
area = southernSettlement1
if user.southernSettlementVisited == False:
print("You step out of your house into the Southern Settlement. You look around and see the king has gone, and in his place the guards still stand discussing the airspeed velocity of various swallow")
spacer1 = input("Press enter to continue")
print("You pick up further bits of their conversation. '...great treasure' '...but no one has been to the capitol since the conflagration'")
spacer2 = input("Press enter to continue")
print("You decide to seek out this great treasure yourself.")
input("Press enter to continue")
print("You've unlocked the Options Menu.")
input("Press enter to continue")
print("You need to prepare for your adventure. You look around town and see the villagers beginning to start their day.")
user.southernSettlementVisited = True
else:
print("You return to the Southern Settlement")
keepGoingSettlement = True
while keepGoingSettlement:
print("""Where would you like to go?
1. Merchant