-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.py
2214 lines (1798 loc) · 97.4 KB
/
game.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
import json
import time
from traceback import print_stack
from termcolor import colored
import random
from playsound import playsound
#https://pypi.org/project/termcolor/ voor meer kleur en text info
#https://asciiflow.com/ om puzzel met ascii te tekenen
class game:
def ReadJson():
JsonFile = open("game.json", "r")
data = json.load(JsonFile)
JsonFile.close()
return data
def WriteJson(data):
with open("game.json", "w") as outfile:
json.dump(data, outfile, indent=2)
outfile.close()
data = ReadJson()
#print json data without the curly brackets
def PrintInventory(data):
print("\nInventory: \n")
for item in data["Inventory"]:
print(item, ":", data["Inventory"][item]["amount"])
print()
def PrintCharacter(data):
print("\nCharacter: \n")
result = '\n'.join(f'{key}: {value}' for key, value in data["Character"].items())
print(result)
def CheckThings(data, info):
print(info, ":", data["Inventory"][info]["info"], "\nAmount:", data["Inventory"][info]["amount"])
def reset(data):
#Run a for loop over each key in the json file and set it to 0 if that is the desired value
for value in dict(data["Character"].items()):
if value == "Hp" or value == "Food":
data["Character"][value] = 100
else:
data["Character"][value] = 0
for value in dict(data["Inventory"].items()):
data["Inventory"][value]["amount"] = 0
if "equipped" in data["Inventory"][value]:
data["Inventory"][value]["equipped"] = False
data["Room"] = 0
game.WriteJson(data)
#Functie om items te equippen
def equip(info, data):
#file = open("game.json", "r")
#items = json.load(file)
#e = info
for item in data:
if "Inventory" in item:
for item2 in data["Inventory"]:
if info in item2:
data["Inventory"][info]["equipped"] = True
print("You have equipped the", info)
game.WriteJson(data)
def unequip(info, data):
#file = open("game.json", "r")
#items = json.load(file)
#e = info
for item in data:
if "Inventory" in item:
for item2 in data["Inventory"]:
if info in item2:
data["Inventory"][info]["equipped"] = False
print("You have unequipped the", info)
game.WriteJson(data)
#Functie om voedsel te consumeren
def food(info, data):
file = open("game.json", "r")
food = json.load(file)
e = info
for item in food:
if "Inventory" in item:
for item2 in food["Inventory"]:
if info in item2:
if e == "Bread" and data["Inventory"][e] > 0 and data["Character"]["Food"] < 100:
data["Character"]["Food"] += 20
data["Inventory"][e]["amount"] -= 1
if data["Character"]["Food"] >= 100:
data["Character"]["Food"] = 100
print("You are full")
print("You have eaten", e)
game.WriteJson(data)
elif e == "DriedMeat" and data["Inventory"][e] > 0 and data["Character"]["Food"] < 100:
data["Character"]["Food"] += 30
data["Inventory"][e]["amount"] -= 1
if data["Character"]["Food"] >= 100:
data["Character"]["Food"] = 100
print("You are full")
print("You have eaten", e)
game.WriteJson(data)
elif e == "Meat" and data["Inventory"][e] > 0 and data["Character"]["Food"] < 100:
data["Character"]["Food"] += 40
data["Inventory"][e]["amount"] -= 1
if data["Character"]["Food"] >= 100:
data["Character"]["Food"] = 100
print("You are full")
print("You have eaten", e)
game.WriteJson(data)
elif e == "Water" and data["Inventory"][e] > 0 and data["Character"]["Food"] < 100:
data["Character"]["Food"] += 5
data["Inventory"][e]["amount"] -= 1
if data["Character"]["Food"] >= 100:
data["Character"]["Food"] = 100
print("You are full")
print("You have drunk", e)
game.WriteJson(data)
def fight(data, enemy):
print("You have encountered a", enemy)
gevecht = input(colored("Attack, Defend or Heal?","red"))
if enemy != "Boss":
#randint between 100 and 200 with with steps of 5
enemyhp = random.randrange(100, 201, 5)
elif enemy == "Wendigo":
enemyhp = random.randrange(200, 301, 5)
else:
enemyhp = 500
if data["Inventory"]["RustySword"]["equipped"] == True:
damage = 10
elif data["Inventory"]["IronSword"]["equipped"] == True:
damage = 20
elif data["Inventory"]["SteelSword"]["equipped"] == True:
damage = 30
else:
damage = 5
while enemyhp > 0 :
print(f"The {enemy} has {enemyhp} hp left and you have {data['Character']['Hp']} hp left")
if gevecht.lower() == "attack":
rand = random.randrange(1, 3)
if rand == 2:
print("You have succesfully attacked")
enemyhp -= damage
print("The enemy has", enemyhp, "hp left")
elif rand == 1 or rand == 3:
print("You have failed to attack")
data["Character"]["Hp"] -= 10
gevecht = ""
elif gevecht.lower() == "defend":
rand = random.randrange(1, 3)
if rand == 2:
print("You have succesfully defended")
else:
print("You have failed to defend")
data["Character"]["Hp"] -= 5
print("You have taken 10 damage")
game.WriteJson(data)
gevecht = ""
elif gevecht.lower() == "heal":
while data["Inventory"]["Herbs"]["amount"] > 2:
data["Inventory"]["Medicine"]["amount"] += 1
data["Inventory"]["Herbs"]["amount"] -= 2
print(f"You have {data['Inventory']['Medicine']} medicine")
game.WriteJson(data)
if data['Inventory']['Medicine']["amount"] > 1 and data["Character"]["Hp"] < 100:
data["Character"]["Hp"] += 25
data["Inventory"]["Medicine"]["amount"] -= 1
elif data["Character"]["Hp"] >= 100:
print("You havent taken any damage")
else:
print("You dont have enough medicine")
gevecht = ""
else:
data["Character"]["Hp"] -= 10
gevecht = input(colored("Attack, Defend or Heal?","red"))
if enemyhp <= 0 and enemy != "Boss":
print("You have defeated the", enemy)
game.LoadRoom(data)
elif enemyhp <= 0 and enemy == "Boss":
print("You have defeated the", enemy)
print("You have won the game")
game.EndScreen(data)
#Als je verder wil gaan met het spel op de laatste plek waar je was
#dan wordt deze functie aangeroepen.
def LoadRoom(data):
if data["Room"] == 0:
print(colored("No savegame, starting new game","red"))
game.reset(data)
game.Pre_Game_Story(data)
elif data["Room"] == 1:
game.room1(data)
elif data["Room"] == 2:
game.room2(data)
elif data["Room"] == 2.5:
game.subroom2(data)
elif data["Room"] == 3:
game.room3(data)
elif data["Room"] == 3.5:
game.subroom3(data)
elif data["Room"] == 4:
game.room4(data)
elif data["Room"] == 5:
game.room5(data)
elif data["Room"] == 5.1:
game.subroom5_1(data)
elif data["Room"] == 5.2:
game.subroom5_2(data)
elif data["Room"] == 5.3:
game.subroom5_3(data)
elif data["Room"] == 6:
game.room6(data)
elif data["Room"] == 6.1:
game.subroom6_1(data)
elif data["Room"] == 6.2:
game.subroom6_2(data)
elif data["Room"] == 7:
game.room7(data)
elif data["Room"] == 8:
game.room8(data)
elif data["Room"] == 9:
game.room9(data)
elif data["Room"] == 10:
game.room10(data)
elif data["Room"] == 10.1:
game.subroom10_1(data)
else:
game.roomboss(data)
#functie waarmee je het spel kan opslaan via een json file
def save(data):
print(colored("\nSaving game...", "red"))
game.WriteJson(data)
time.sleep(0.5)
print(colored("\nSaved Game!", "red"))
game.LoadRoom(data)
#Functie dat wordt aangeroepen als je help schrijft
def help():
print("HELP: \n")
print("You can write different commands to look around the room")
print("You can write the following commands: ")
print("INVENTORY: to see your inventory")
print("INSPECT: to inspect an item")
print("CHARACTER: to see your character")
print("LOOK: to look around the room")
print("GO: if you write go and then a statement that has been said when looking around a room you can go check that place.")
print("EAT: to eat something")
print("DRINK: to drink something")
print("FIGHT: to fight a monster")
print("TALK: to talk to a character")
print("PICKUP: to pick up an item")
print("EQUIP: to equip an item")
print("UNEQUIP: to unequip an item")
print("SAVE: to save the game")
print("EXIT: to exit the game")
print("HELP: to see this menu again")
print("")
def start(data):
begin = input("Do you want to start the game or resume with the latest save? ")
while begin != "start" and begin != "resume":
print(colored("Please enter start or resume","red"))
begin = input("Do you want to start the game or resume with the latest save? ")
if begin == "start":
game.reset(data)
game.Pre_Game_Story(data)
#reset json data
else:
#Uiteindelijk de juiste ruimte aanroepen dat in de json file is opgeslagen
print(f"resuming game in room {data['Room']}")
print("This is the inventory u saved: ")
game.PrintInventory(data)
game.LoadRoom(data)
#De functie die in het begin wordt aangeroepen om het verhaal te starten
def Pre_Game_Story(data):
print(colored("You can write different commands to look around the room (Write HELP for more info WHEN ASKED FOR A COMMAND)...","red",attrs=['bold','underline']))
data["Character"]["Name"] = input(colored("What is the name you want to give your character? ","green"))
game.WriteJson(data)
print("\nYou suddenly wake up with the worst headache you have ever had.")
print("You don't know where you are and you don't know how you got here.")
print("You only know that you want to climb the mountain and slay the boss.")
game.room1(data)
def room1(data):
data["Room"] = 1
game.WriteJson(data)
command = input(colored("\nType a valid command... ","green"))
while command.lower() != "go door":
if command.lower() == "help":
game.help()
command = ""
elif command.lower() == "inventory":
game.PrintInventory(data)
command = ""
elif command.lower().__contains__("inspect"):
command2 = command.split()
game.CheckThings(data, command2[1])
command = ""
elif command.lower() == "character":
game.PrintCharacter(data)
command = ""
elif command.lower() == "look":
print("\nYou look around the room and notice that it is a nice cozy cabin in the woods.\n"
"You also notice that there is a closet as well as a fridge.\nThere is also a nice"
"wall with a paint on it.")
command = ""
elif command.lower() == "check closet":
print("\nYou check the closet and find some nice and warm winter clothes which you put in your inventory.")
data["Inventory"]["WinterClothes"]["amount"] += 1
data["Inventory"]["Coins"] += 400
game.WriteJson(data)
command = ""
elif command.lower() == "check wall":
print("\nYou go to the wall and find some shoes which you stash in your inventory.\n"
"You also see a weard painting.")
data["Inventory"]["Shoes"]["amount"] += 1
game.WriteJson(data)
command = ""
elif command.lower() == "check painting":
print("\n You check the painting and find that there is nothing wrong with it.")
print("You find that the painting is a beautiful painting of the mountains right outside this cottage.")
command = ""
elif command.__contains__("unequip") or command.__contains__("UNEQUIP"):
command2 = command.split()
game.unequip(command2[1], data)
command = ""
elif command.__contains__("equip") or command.__contains__("EQUIP"):
command2 = command.split()
game.equip(command2[1], data)
command = ""
elif command.__contains__("eat") or command.__contains__("EAT"):
command2 = command.split()
game.food(command2[1], data)
command = ""
elif command.__contains__("drink") or command.__contains__("DRINK"):
command2 = command.split()
game.food(command2[1], data)
command = ""
elif command.lower() == "check fridge":
print("\nYou check the fridge and find some nice food to take with you on the journey.")
data["Inventory"]["Bread"]["amount"] += 1
data["Inventory"]["Water"]["amount"] += 4
data["Inventory"]["Meat"]["amount"] += 3
game.WriteJson(data)
command = ""
elif command.lower() == "save":
command = ""
game.save(data)
elif command.lower() == "exit":
print(colored("Exiting game...","red"))
exit()
elif command.lower() == "go further":
game.room2(data)
elif command.lower() == "go back":
print("Not able to go back")
else:
command = input(colored("\nType a valid command... ","green"))
if data["Inventory"]["WinterClothes"]["amount"] == 0 or data["Inventory"]["Shoes"]["amount"] == 0:
print("It is cold outside, check if you can find some clothing and shoes.")
game.room1(data)
else:
print("\nYou go through the door and find yourself in a opening in the forest.")
game.room2(data)
def room2(data):
data["Room"] = 2
game.WriteJson(data)
command = input(colored("\nType a valid command... ","green"))
while command.lower() != "go path" or command.lower() != "go back":
if command.lower() == "help":
game.help()
command = ""
elif command.lower() == "inventory":
game.PrintInventory(data)
command = ""
elif command.lower() == "character":
game.PrintCharacter(data)
command = ""
elif command.lower().__contains__("inspect"):
command2 = command.split()
game.CheckThings(data, command2[1])
command = ""
elif command.lower() == "look":
print("\n.When you look around u can see a small shed.\n"
"In the distance you see the opening to a path through the forest.")
command = ""
elif command.lower() == "check Shed":
print("\nYou check the shed and find a piece of rope and a set of climbing picks.")
data["Inventory"]["WinterClothes"]["amount"] = 1
game.WriteJson(data)
command = ""
elif command.__contains__("unequip") or command.__contains__("UNEQUIP"):
command2 = command.split()
game.unequip(command2[1], data)
command = ""
elif command.__contains__("equip") or command.__contains__("EQUIP"):
command2 = command.split()
game.equip(command2[1], data)
command = ""
elif command.__contains__("eat") or command.__contains__("EAT"):
command2 = command.split()
game.food(command2[1], data)
command = ""
elif command.__contains__("drink") or command.__contains__("DRINK"):
command2 = command.split()
game.food(command2[1], data)
command = ""
elif command.lower() == "save":
command = ""
game.save(data)
elif command.lower() == "exit":
print(colored("Exiting game...","red"))
exit()
else:
command = input(colored("\nType a valid command... ","green"))
if command.lower() == "go back":
print("\nU go back to where u came from.")
game.room1(data)
elif command.lower() == "go path":
print(colored("\nYou walk onto the path and stand infront of a decision, will you look around or go further... ","grey"))
game.subroom2(data)
def subroom2(data):
data["Room"] = 2.5
game.WriteJson(data)
command = input(colored("\nType a valid command... ","green"))
while command.lower() != "go further" or command.lower() != "go back":
if command.lower() == "help":
game.help()
command = ""
elif command.lower() == "inventory":
game.PrintInventory(data)
command = ""
elif command.lower() == "character":
game.PrintCharacter(data)
command = ""
elif command.lower().__contains__("inspect"):
command2 = command.split()
game.CheckThings(data, command2[1])
command = ""
elif command.lower() == "look":
print("\n.When you look around u can see that the path is encased in bushes and trees.\n"
"Maybe you can find some herbs and wood to help you in your journey")
command = ""
elif command.lower() == "check bushes":
print("\nYou check the bushes and find some wood and a maybe few weird herbs.")
data["Inventory"]["Wood"]["amount"] += 3
BurkingBagCounter = int(random(1,100))
if BurkingBagCounter <= 50:
data["Inventory"]["Herbs"]["amount"] += 2
elif BurkingBagCounter > 50 and BurkingBagCounter <= 75:
data["Inventory"]["Herbs"]["amount"] += 5
else:
print("You find no herbs")
game.WriteJson(data)
command = ""
elif command.lower() == "check bushes":
print("\nYou go to the wall and find some shoes which you stash in your inventory.\n"
"You also see a weard painting.")
data["Inventory"]["Shoes"]["amount"] = 1
game.WriteJson(data)
command = ""
elif command.__contains__("unequip") or command.__contains__("UNEQUIP"):
command2 = command.split()
game.unequip(command2[1], data)
command = ""
elif command.__contains__("equip") or command.__contains__("EQUIP"):
command2 = command.split()
game.equip(command2[1], data)
command = ""
elif command.__contains__("eat") or command.__contains__("EAT"):
command2 = command.split()
game.food(command2[1], data)
command = ""
elif command.__contains__("drink") or command.__contains__("DRINK"):
command2 = command.split()
game.food(command2[1], data)
command = ""
elif command.lower() == "save":
command = ""
game.save(data)
elif command.lower() == "exit":
print(colored("Exiting game...","red"))
exit()
else:
command = input(colored("\nType a valid command... ","green"))
if command.lower() == "go back":
print("\nU go back to where u came from.")
game.room2(data)
elif command.lower() == "go further":
print(colored("\nYou further on the path and eventually arrive at a steep stone cliff.... ","grey"))
game.room3(data)
#De eerste opstakel waar je tegen aan loopt, en je omhoog klimt
def room3(data):
data["Room"] = 3
game.WriteJson(data)
print("You feel that you are strong enough to climb up this cliff. Because it seems that it is only ten meters tall.")
#time.sleep(5)
command = input(colored("\nType a valid command... ", "green"))
while command.lower() != "go wall":
if command.lower() == "help":
game.help()
command = ""
elif command.lower() == "inventory":
game.PrintInventory(data)
command = ""
elif command.lower() == "character":
game.PrintCharacter(data)
command = ""
elif command.lower().__contains__("inspect"):
command2 = command.split()
game.CheckThings(data, command2[1])
command = ""
elif command.lower() == "look":
print("\nYou look around to see if you can find something that you can work with.")
#if(random.randint(0,100) > 30):
print("You luckily notice that there is a crack in the wall.")
print("The wall before you just seems like it got a little taller.")
print("But it does not seem impossible to climb")
command = ""
elif command.lower() == "climb wall":
print("\n You walk to the large wall which is only ten meters high.")
print("You have the confidence to conquer this wall because it is not that tall.")
break
elif command.lower() == "check crack":
print("\nYou check the crack that you have previously seen when taking a look around.\n"
"And you notice that it is just big enough for your body to go through.\n")
command = ""
elif command.lower() == "go crack":
print("\nYou manage to squeeze yourself through the crack.")
game.subroom3(data)
command = ""
elif command.lower() == "go pathway":
game.room2(data)
command = ""
elif command.__contains__("unequip") or command.__contains__("UNEQUIP"):
command2 = command.split()
game.unequip(command2[1], data)
command = ""
elif command.__contains__("equip") or command.__contains__("EQUIP"):
command2 = command.split()
game.equip(command2[1], data)
command = ""
elif command.__contains__("eat") or command.__contains__("EAT"):
command2 = command.split()
game.food(command2[1], data)
command = ""
elif command.__contains__("drink") or command.__contains__("DRINK"):
command2 = command.split()
game.food(command2[1], data)
command = ""
elif command.lower() == "previous room":
game.room2(data)
command = ""
elif command.lower() == "save":
command = ""
game.save(data)
elif command.lower() == "exit":
print(colored("Exiting game...","red"))
exit()
elif command.lower() == "go further":
game.room4(data)
elif command.lower() == "go back":
game.room2(data)
else:
command = input(colored("\nType a valid command... ","green"))
if command == "climb wall":
if data["Inventory"]["climbing picks"]["amount"] >= 1:
print("\nYou climb the wall with the help of your climbing picks.")
game.room4(data)
else:
print("\nYou can't climb the wall with your bare hands.")
game.room3(data)
else:
if data["Inventory"]["climbing picks"]["amount"] >= 1:
print("\nYou climb the wall with the help of your climbing picks.")
game.room4(data)
else:
print("\nYou can't climb the wall with your bare hands.")
game.room3(data)
#Geheime cave in de eerste muur waar je langs moet klimmen
def subroom3(data):
data["Room"] = 3.5
game.WriteJson(data)
print("\nYou have entered a subroom of stage 3.")
command = input(colored("\nType a valid command... ","green"))
while command.lower() != "go crack":
command2 = command.split()
if command.lower() == "help":
game.help()
command = ""
elif command.lower() == "inventory":
game.PrintInventory(data)
command = ""
elif command.lower() == "character":
game.PrintCharacter(data)
command = ""
elif command.lower().__contains__("inspect"):
command2 = command.split()
game.CheckThings(data, command2[1])
command = ""
elif command.lower() == "look":
print("You look around the dimly lit cave to see a skeleton leaning against the wall.")
print("Behind you is the crack where you came through.")
command = ""
elif command.lower() == "check skeleton":
print("Upon checking the skeleton you find a small bag containing 700 coins.")
print("You also find a rusty old sword and an old helmet.\n")
data["Inventory"]["RustySword"]["amount"] = 1
data["Inventory"]["Coins"]["amount"] += 700
data["Inventory"]["OldHelmet"]["amount"] = 1
game.WriteJson(data)
command = ""
elif command.lower() == "go crack":
print("You are leaving the small cave")
command = ""
elif command.__contains__("unequip") or command.__contains__("UNEQUIP"):
command2 = command.split()
game.unequip(command2[1], data)
command = ""
elif command.__contains__("equip") or command.__contains__("EQUIP"):
command2 = command.split()
game.equip(command2[1], data)
command = ""
elif command.__contains__("eat") or command.__contains__("EAT"):
command2 = command.split()
game.food(command2[1], data)
command = ""
elif command.__contains__("drink") or command.__contains__("DRINK"):
command2 = command.split()
game.food(command2[1], data)
command = ""
elif command.lower() == "save":
command = ""
game.save(data)
elif command.lower() == "exit":
print(colored("Exiting game...","red"))
exit()
else:
command = input(colored("\nType a valid command... ","green"))
print("You are leaving the small cave")
game.WriteJson(data)
game.room3(data)
def room4(data):
data["Room"] = 4
game.WriteJson(data)
print("\nYou can search for herbs using: search herbs")
command = input(colored("\n Type a valid command... ", "green"))
while command.lower() != "go further" and command.lower() != "go back":
command2 = command.split()
command2[0] = command2[0].lower()
if command.lower() == "help":
game.help()
command = ""
elif command.lower() == "inventory":
game.PrintInventory(data)
command = ""
elif command.lower() == "character":
game.PrintCharacter(data)
command = ""
elif command.lower().__contains__("inspect"):
command2 = command.split()
game.CheckThings(data, command2[1])
command = ""
elif command.__contains__("unequip") or command.__contains__("UNEQUIP"):
command2 = command.split()
game.unequip(command2[1], data)
command = ""
elif command.__contains__("equip") or command.__contains__("EQUIP"):
command2 = command.split()
game.equip(command2[1], data)
command = ""
elif command.__contains__("eat") or command.__contains__("EAT"):
command2 = command.split()
game.food(command2[1], data)
command = ""
elif command.__contains__("drink") or command.__contains__("DRINK"):
command2 = command.split()
game.food(command2[1], data)
command = ""
elif command.lower() == "search herbs":
timeToSeek = input(" How long do you want to search for herbs? (1-10) ")
for i in range(int(timeToSeek)):
print("Searching for herbs...")
randomHerbNumber = random.randrange(0, 11,2)
data["Inventory"]["Herbs"]["amount"] += (randomHerbNumber*2)
time.sleep(1)
command = ""
elif command.lower() == "save":
command = ""
game.save(data)
elif command.lower() == "exit":
print(colored("Exiting game...","red"))
exit()
else:
command = input(colored("\n Type a valid command... ", "green"))
if command.lower() == "go further":
game.room5(data)
elif command.lower() == "go back":
game.room3(data)
#Het bergdorpje
def room5(data):
data["Room"] = 5
game.WriteJson(data)
print("\nYou have arrived in the miners town of Miners Vale.")
command = input(colored("\n Type a valid command... ", "green"))
while command.lower() != "go Watchtower":
command2 = command.split()
command2[0] = command2[0].lower()
if command.lower() == "help":
game.help()
command = ""
elif command.lower() == "inventory":
game.PrintInventory(data)
command = ""
elif command.lower() == "character":
game.PrintCharacter(data)
command = ""
elif command.lower().__contains__("inspect"):
command2 = command.split()
game.CheckThings(data, command2[1])
command = ""
elif command.lower() == "look":
print("\nYou take a look around the small miners town and see three handy building.")
print("The three buildings that are open right now are the tavern, the hotel and the store.")
print("At the tavern you can have a nice drink for a cheap price and talk with the locals.")
print("The hotel is obviously for sleeping and you can buy useful items at the store.")
command = ""
elif command.__contains__("unequip") or command.__contains__("UNEQUIP"):
command2 = command.split()
game.unequip(command2[1], data)
command = ""
elif command.__contains__("equip") or command.__contains__("EQUIP"):
command2 = command.split()
game.equip(command2[1], data)
command = ""
elif command.__contains__("eat") or command.__contains__("EAT"):
command2 = command.split()
game.food(command2[1], data)
command = ""
elif command.__contains__("drink") or command.__contains__("DRINK"):
command2 = command.split()
game.food(command2[1], data)
command = ""
elif command.lower() == "go tavern":
print("\nYou walk over to the tavern to check it out.")
game.subroom5_1(data)
command = ""
elif command.lower() == "go hotel":
print("\nYou walk over to the hotel to check if they have a cheap room available for you.")
game.subroom5_2(data)
command = ""
elif command.lower() == "go store":
print("\nYou walk over to the tavern to check if they have useful items that you can buy for your climb and fight with the evil monsters.")
game.subroom5_3(data)
command = ""
elif command.lower() == "go Watchtower":
print("\nYou leave the village and start walking to the watchtower.")
elif command.lower() == "previous room":
game.room4(data)
elif command.lower() == "save":
command = ""
game.save(data)
elif command.lower() == "exit":
print(colored("Exiting game...","red"))
exit()
else:
command = input(colored("\n Type a valid command... ", "green"))
print("\nYou leave the village and start walking to the watchtower.")
game.room6(data)
#De bar in het hotel bergdorpje
def subroom5_1(data):
data["Room"] = 5.1
game.WriteJson(data)
print("\nYou arrived in the tavern where you can eat and drink and maybe gather some useful information.")
command = input(colored("\n Type a valid command... ", "green"))
while command.lower() != "leave tavern":
if command.lower() == "help":
game.help()
command = ""
elif command.lower() == "inventory":
game.PrintInventory(data)
command = ""
elif command.lower() == "character":
game.PrintCharacter(data)
command = ""
elif command.lower().__contains__("inspect"):
command2 = command.split()
game.CheckThings(data, command2[1])
command = ""
elif command.lower() == "look":
print("\nYou see two people whilst looking through the tavern.")
print("One is the bartender and the other is a guest.")
print("Watch out for the guest thoug, because you have a small chance to end up in a fight")
command = ""
elif command.lower() == "talk guest":
print("The guest asks you are you an adventurer, where you answer yes.")
print("He says to you in an ominous voice: 'Don't climb the mountain, it is dangerous and filled with strong monsters.'")
print("'If you still plan to go then you need to check out the old watchtower, it is said to contain some nice loot.'")
print("You thank the guest and go back to your own table")
command = ""
elif command.lower() == "talk bartender":
print("You go talk with the bartender and says that you can buy a meal or a beer. For 100 coins each")
print("He asks if you'd like to have something.")
command = ""
elif command.lower() == "buy beer":
if (data["Inventory"]["Coins"]["amount"] - 100) < 0:
print("Insufficient funds")
command = ""
else:
print("You bought a nice beer for 100 coins and feel your saturation going up.")
data["Character"]["Food"] += 20
data["Inventory"]["Coins"]["amount"] -= 100
time.sleep(2)
print("Food went up by 20")
left = data["Inventory"]["Coins"]["amount"]
game.WriteJson(data)
print(f"You have {left} Coins left")
command = ""
elif command.lower() == "buy food":
if (data["Inventory"]["Coins"]["amount"] - 100) < 0:
print("Insufficient funds")
else:
print("You bought yourself a nice and hot meal for 100 coins and fill yourselves.")
data["Character"]["Food"] += 30
data["Inventory"]["Coins"]["amount"] -= 100