-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMain - Dacha game
More file actions
1104 lines (1104 loc) · 55.6 KB
/
Main - Dacha game
File metadata and controls
1104 lines (1104 loc) · 55.6 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
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
{
"cells": [
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 85
},
"id": "uRjaA6neUGcr",
"outputId": "26d6a096-bc21-4165-819d-f4277543cab4"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Requirement already satisfied: soundfile in c:\\users\\eloi pc\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages (0.10.3.post1)\n",
"Requirement already satisfied: cffi>=1.0 in c:\\users\\eloi pc\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages (from soundfile) (1.14.2)\n",
"Requirement already satisfied: pycparser in c:\\users\\eloi pc\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages (from cffi>=1.0->soundfile) (2.20)\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"WARNING: You are using pip version 20.1.1; however, version 20.2.4 is available.\n",
"You should consider upgrading via the 'c:\\users\\eloi pc\\appdata\\local\\programs\\python\\python38-32\\python.exe -m pip install --upgrade pip' command.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Requirement already satisfied: playsound in c:\\users\\eloi pc\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages (1.2.2)\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"WARNING: You are using pip version 20.1.1; however, version 20.2.4 is available.\n",
"You should consider upgrading via the 'c:\\users\\eloi pc\\appdata\\local\\programs\\python\\python38-32\\python.exe -m pip install --upgrade pip' command.\n"
]
}
],
"source": [
"# Here we should import all packages and define other things such as classes\n",
"import time\n",
"import numpy as np\n",
"import pandas as pd\n",
"from IPython.display import Audio\n",
"from IPython.display import Image\n",
"from IPython.display import display\n",
"\n",
"import multiprocessing\n",
"!pip install soundfile\n",
"import soundfile as sf\n",
"!pip install playsound\n",
"from playsound import playsound\n",
"\n",
"class color:\n",
" ### How to use:\n",
" ### print(color.BOLD + 'Hello World !' + color.END)\n",
" ### print(color.DARKCYAN + color.BOLD + 'Hello World !' + color.END)\n",
" PURPLE = '\\033[95m'\n",
" CYAN = '\\033[96m'\n",
" DARKCYAN = '\\033[36m'\n",
" BLUE = '\\033[94m'\n",
" GREEN = '\\033[92m'\n",
" YELLOW = '\\033[93m'\n",
" RED = '\\033[91m'\n",
" BOLD = '\\033[1m'\n",
" UNDERLINE = '\\033[4m'\n",
" END = '\\033[0m'\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 71,
"metadata": {
"id": "IHF3ccywR3zo"
},
"outputs": [],
"source": [
"# Object declaration/initialization.\n",
"\n",
"# RUI: Library of Images and sounds\n",
"# [RUI: to be done, now dummy data just to test // sounds will not run properly on colaborative]\n",
"map_game_room = Image(filename=\"sounds_and_images\\map_game_room.png\")\n",
"map_corridor = Image(filename=\"sounds_and_images\\map_corridor.png\")\n",
"map_bathroom = Image(filename=\"sounds_and_images\\map_bathroom.png\")\n",
"map_kitchen = Image(filename=\"sounds_and_images\\map_kitchen.png\")\n",
"map_living_room = Image(filename=\"sounds_and_images\\map_living_room.png\")\n",
"\n",
"#[Rui, these soun]\n",
"sound_bathtub = \"sounds_and_images\\clogged_bathtub.wav\"\n",
"sound_old_lady = \"sounds_and_images\\gulping_bottle.wav\"\n",
"sound_cutlery_drawer = \"sounds_and_images\\smashing_wood.wav\"\n",
"\n",
"# [RUI: This one could be called maybe when we write \"congratulations\".]\n",
"sound_victory = \"sounds_and_images\\win.wav\"\n",
"# [RUI: This one can be called maybe when we call the function to get the next room.]\n",
"sound_door_creaking = \"sounds_and_images\\door_creaking.wav\"\n",
"\n",
"# Definition of ROOMS:\n",
"game_room = {\n",
" \"name\": \"game room\",\n",
" \"type\": \"room\",\n",
" \"map\": map_game_room}\n",
"corridor = {\n",
" \"name\": \"corridor\",\n",
" \"type\": \"room\",\n",
" \"map\": map_corridor}\n",
"bathroom = {\n",
" \"name\": \"bathroom\",\n",
" \"type\": \"room\",\n",
" \"map\": map_bathroom}\n",
"kitchen = {\n",
" \"name\": \"kitchen\",\n",
" \"type\": \"room\",\n",
" \"map\": map_kitchen}\n",
"living_room = {\n",
" \"name\": \"living room\",\n",
" \"type\": \"room\",\n",
" \"map\": map_living_room}\n",
"\n",
"# Definition of DOORS\n",
"door_gameroom = {\n",
" \"name\": \"game room door\",\n",
" \"type\": \"door\",}\n",
"door_bathroom = {\n",
" \"name\": \"bathroom door\",\n",
" \"type\": \"door\",}\n",
"door_kitchen = {\n",
" \"name\": \"kitchen door\",\n",
" \"type\": \"door\",}\n",
"door_livingroom = {\n",
" \"name\": \"living room door\",\n",
" \"type\": \"door\",}\n",
"door_other = {\n",
" \"name\": \"other door\",\n",
" \"type\": \"door\",}\n",
"\n",
"# FURNITURE AND PEOPLE\n",
"\n",
"# GAME ROOM\n",
"side_table = {\n",
" \"name\": \"side table\",\n",
" \"type\": \"furniture\",\n",
" \"useful\": False,\n",
" #flavour_text of side table is set at start with the start game function.\n",
" \"flavour_text\": \"\"}\n",
"couch = {\n",
" \"name\": \"couch\",\n",
" \"type\": \"furniture\",\n",
" \"useful\": False,\n",
" \"flavour_text\": \"Potato.\",\n",
"}\n",
"piano = {\n",
" \"name\": \"piano\",\n",
" \"type\": \"furniture\",\n",
" \"useful\": True,\n",
" \"status\": \"closed\",\n",
" \"code\": \"9857\",\n",
" \"flavour_text\": \"You would be surprised if it was working.\",\n",
"}\n",
"chairs = {\n",
" \"name\": \"chairs\",\n",
" \"type\": \"furniture\",\n",
" \"useful\": False,\n",
" \"flavour_text\": \"Previously owned by a dictator.\",\n",
"}\n",
"bookshelf = {\n",
" \"name\": \"bookshelf\",\n",
" \"type\": \"furniture\",\n",
" \"useful\": True,\n",
" \"books_in_russian\": [\"Преступление и наказание\",\"Маленькие женщины\",\"Большие надежды\",\"Война и мир\",\"Les Misérables\",\"Записки из метро\", \"Белые ночи\", \"Сон о смехотворном человеке\",\"Идиот\",\"Женщина в белом\",\"Отцы и сыновья\",\"Лунный камень\",\"Сайлас Марнер\",\"Путешествие к центру Земли\",\"Мельница на зубной нити\",\"Русско-английский словарь/English–Russian Dictionary\",\"книга джунглей\"],\n",
" \"books_in_english\": [\"Crime and Punishment\",\"Little Women\",\"Great Expectations\",\"War and Peace\",\"Les Misérables\", \"Notes from Underground\",\"White Nights\",\"Dreams of a ridiculous man\",\"The Idiot\",\"The Woman in White\",\"Fathers and Sons\",\"The Moonstone\",\"Silas Marner\",\"Journey to the Center of the Earth\",\"The Mill on the Floss\",\"Russian-English Dictionary/English–Russian Dictionary\",\"The Jungle Book\"],\n",
" \"flavour_text\": \"Packed!\",\n",
" # Bookshelf will have another property key \"play\" with a function attributed as value.\n",
"}\n",
"wall_clock = {\n",
" \"name\": \"wall clock\",\n",
" \"type\": \"furniture\",\n",
" \"useful\": False,\n",
" \"flavour_text\": color.BOLD + \"Antique! \" + color.END + \"Would be worth millions if it was not broken, cracked nor the home of a million of bugs.\",\n",
"}\n",
"piano = {\n",
" \"name\": \"piano\",\n",
" \"type\": \"furniture\",\n",
" \"useful\": True,\n",
" \"password\": \"9857\",\n",
" \"flavour_text\": \"Cords and... bones. Even not creepy pianos have bones\",\n",
"}\n",
"\n",
"# CORRIDOR\n",
"vault = {\n",
" \"name\": \"vault\",\n",
" \"type\": \"furniture\",\n",
" \"password\": \"volga\",\n",
" \"useful\": True,\n",
" \"flavour_text\": \"The lock has a message: \\\"For the sake of the future of this family, the answer is kept secret in the very heart of this great surname.\\\" <<F.I. Oglav>>\",\n",
"}\n",
"old_picture = {\n",
" \"name\": \"old picture\",\n",
" \"type\": \"furniture\",\n",
" \"useful\": False,\n",
" \"flavour_text\": \"2.8 - Oglav family at their Dacha close by a famous river.\",\n",
"}\n",
"# BATHROOM\n",
"bathtub = {\n",
" \"name\": \"bathtub\",\n",
" \"type\": \"furniture\",\n",
" \"useful\": True,\n",
" \"counter\": 0,\n",
" \"flavour_text\": \"The bathtub is filled with rain from the gap on the ceiling\",\n",
" \"sound\": sound_bathtub}\n",
"toilet = {\n",
" \"name\": \"toilet\",\n",
" \"type\": \"furniture\",\n",
" \"useful\": True,\n",
" \"flavour_text\": \"There's no time for number 1's or 2's, you have to leave this dacha!\",}\n",
"sink = {\n",
" \"name\": \"sink\",\n",
" \"type\": \"furniture\",\n",
" \"useful\": True,\n",
" \"flavour_text\": \"You feel bad for breaking the sink but you ain't no plumer\",}\n",
"cabinet = {\n",
" \"name\": \"toilet\",\n",
" \"type\": \"furniture\",\n",
" \"useful\": False,\n",
" \"flavour_text\": \"There is a shatered mirror and a small medicine box that says аспирин 3,5 миллиграмма\",}\n",
"rug = {\n",
" \"name\": \"rug\",\n",
" \"type\": \"furniture\",\n",
" \"useful\": True,\n",
" \"flavour_text\": \"Who the hell has a rug on a bathroom? I’ll keep looking somewhere else, maybe on the bathtub?\",}\n",
"\n",
"# KITCHEN\n",
"plate_cabinet = {\n",
" \"name\": \"plate cabinet\",\n",
" \"type\": \"furniture\",\n",
" \"useful\": False,\n",
" \"flavour_text\": \"Just some old fancy plates.\"\n",
"}\n",
"cutlery_drawer = {\n",
" \"name\": \"cutlery drawer\",\n",
" \"type\": \"furniture\",\n",
" \"useful\": True,\n",
" \"flavour_text\": \"It is full of stuff and things, nothing useful though.\",\n",
" \"sound\": sound_cutlery_drawer\n",
"}\n",
"table_with_chairs = {\n",
" \"name\": \"old table with chairs\",\n",
" \"type\": \"furniture\",\n",
" \"useful\": False,\n",
" \"flavour_text\": \"There are some cutlery and an old tsarist newspaper that says: \\\"Правда - 22 апреля 1912 года\\\". \\n It seems that reading a dictionary doesn't make you that fluent after all!\"\n",
"}\n",
"pantry = {\n",
" \"name\": \"pantry\",\n",
" \"type\": \"furniture\",\n",
" \"useful\": True,\n",
" \"object\": [\"wine\" , \"food can\"],\n",
" \"flavour_text\": \"It's full of food cans and wine bottles from another era, the tags barely visible.\"\n",
"}\n",
"stove_oven = {\n",
" \"name\": \"oven\",\n",
" \"type\": \"furniture\",\n",
" \"useful\": True,\n",
" \"password\": \"1890\",\n",
" \"flavour_text\": \"It is an old stove, the wood fueled kind. It is very scratched... life took a toll on it. \\n There is a small lock to open it, with 4 rotating numerical pieces.\",\n",
"}\n",
"# LIVING ROOM\n",
"old_lady = {\n",
" \"name\": \"old lady\",\n",
" \"type\": \"furniture\",\n",
" \"status\": \"sleeping\",\n",
" \"useful\": True,\n",
" \"flavour_text\": \"All dressed in black, no teeth and sitted on a wooden chair. You doubt she is still alive\",\n",
" \"sound\": sound_old_lady\n",
"}\n",
"pendulum = {\n",
" \"name\": \"pendulum\",\n",
" \"type\": \"furniture\",\n",
" \"useful\": True,\n",
" \"status\": \"closed\",\n",
" \"code\": \"0915\",\n",
" \"flavour_text\": \"What a gorgeous clock this must have been.\",\n",
"}\n",
"crib = {\n",
" \"name\": \"crib\",\n",
" \"type\": \"furniture\",\n",
" \"useful\": True,\n",
" \"flavour_text\": \"Do you really felt like checking this twice?\",\n",
"}\n",
"\n",
"# KNOWLEDGE\n",
"\n",
"russian = {\n",
"#Learn from bookshelf interaction\n",
" \"name\": \"russian\",\n",
" \"type\": \"knowledge\",\n",
" \"target\": side_table,\n",
"}\n",
"\n",
"wrench = {\n",
" \"name\": \"wrench\",\n",
" \"type\": \"knowledge\",\n",
" \"target\": sink,}\n",
"lever = {\n",
" \"name\": \"lever\",\n",
" \"type\": \"knowledge\",\n",
" \"target\": toilet,}\n",
"wine = {\n",
" \"name\": \"open wine\",\n",
" \"type\": \"knowledge\",\n",
" \"target\": old_lady}\n",
"wine_opener = {\n",
" \"name\": \"wine opener\",\n",
" \"type\": \"knowledge\",\n",
" \"target\": wine}\n",
"keys_pendulum = {\n",
" \"name\": \"keys pendulum\",\n",
" \"type\": \"knowledge\",\n",
" \"target\": pendulum, }\n",
"hammer = {\n",
" \"name\": \"hammer\",\n",
" \"type\": \"knowledge\",\n",
" \"target\": cutlery_drawer}\n",
"\n",
"\n",
"#KEYS\n",
"key_gameroom = {\n",
" \"name\": \"key for game room\",\n",
" \"type\": \"key\",\n",
" \"target\": door_gameroom,}\n",
"key_bathroom = {\n",
" \"name\": \"key for bathroom\",\n",
" \"type\": \"key\",\n",
" \"target\": door_bathroom,}\n",
"key_kitchen = {\n",
" \"name\": \"key for kitchen\",\n",
" \"type\": \"key\",\n",
" \"target\": door_kitchen,}\n",
"key_livingroom = {\n",
" \"name\": \"key for living room\",\n",
" \"type\": \"key\",\n",
" \"target\": door_livingroom,}\n",
"key_outside = {\n",
" \"name\": \"key for outside\",\n",
" \"type\": \"key\",\n",
" \"target\": door_other,}\n",
"\n",
"\n",
"# OUTSIDE\n",
"outside = {\n",
" \"name\": \"outside\"}\n",
"\n",
"# ALL\n",
"all_rooms = [game_room, corridor, bathroom, kitchen, living_room, outside]\n",
"all_doors = [door_gameroom, door_bathroom, door_livingroom, door_kitchen, door_other]\n",
"all_knowledge = [bookshelf, wrench, lever, wine_opener, wine, hammer]\n",
"# Here we should define all object relations\n",
" # At least these should be: \n",
" # For rooms: which objects (furnitures and doors - probably not knowledge) it contains.\n",
" # For furniture/people: which items(keys) it contains.\n",
" # For doors: which rooms they connect.\n",
" \n",
"object_relations = {\n",
" \"game room\": [couch, chairs, bookshelf, piano, side_table, wall_clock, door_gameroom],\n",
" \"bathroom\":[toilet, bathtub, sink, cabinet, rug, door_bathroom],\n",
" \"corridor\": [old_picture, vault, door_gameroom, door_bathroom, door_kitchen, door_livingroom],\n",
" \"kitchen\": [plate_cabinet, cutlery_drawer, stove_oven, table_with_chairs, pantry, door_kitchen],\n",
" \"living room\": [old_lady, pendulum, crib, door_livingroom, door_other],\n",
"\n",
" \"book shelf\": [key_gameroom],\n",
" \"vault\": [key_bathroom],\n",
"\n",
" #### RUI: Would making this Rug lower case (rug) make any difference ? It is lower case everywhere else.\n",
" \"Rug\": [key_kitchen],\n",
" \"oven\": [key_livingroom],\n",
" \"piano\": [key_outside],\n",
" \n",
"\n",
" \"bathtub\": [lever],\n",
" \"toilet\": [wrench],\n",
"\n",
" \"game room door\": [game_room, corridor],\n",
" \"living room door\": [corridor, living_room],\n",
" \"kitchen door\": [corridor, kitchen],\n",
" \"bathroom door\": [corridor, bathroom],\n",
" \"other door\": [living_room, outside],\n",
"\n",
" \"outside\": [door_other],\n",
"\n",
"}\n",
"# Here we need to define the original/starting state of the game.\n",
"# We need to say which is the starting room.\n",
"# We need to make empty lists for our keys_collected or for our knowledge.\n",
"# We need to establish the target (which is outside.) \n",
"\n",
"INIT_GAME_STATE = {\n",
" \"current_room\": game_room,\n",
" \"keys_collected\": [],\n",
" \"knowledge_collected\": [],\n",
" \"map_collected\": [game_room],\n",
" \"target_room\": outside\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 72,
"metadata": {
"id": "pVI6VLkaS-lN"
},
"outputs": [],
"source": [
"# Here we should try to put all new functions of general use we make\n",
"def linebreak():\n",
" \"\"\"\n",
" Print a line break\n",
" \"\"\"\n",
" print(\"\\n\")\n",
"\n",
"def play_my_sound(audio_string):\n",
" f = sf.SoundFile(audio_string)\n",
" lengh_audio = len(f) / f.samplerate\n",
" p = multiprocessing.Process(target=playsound, args=(audio_string,))\n",
" p.start()\n",
" time.sleep(lengh_audio)\n",
" p.terminate()\n",
"\n",
"def keys_in_pocket():\n",
" \"\"\"\n",
" List all keys currently obtained.\n",
" \"\"\"\n",
" #The for-loop gets all key_names. \n",
" #It looks inside the game_state dictonary for the value corresponding to the \"keys_collected\" key.\n",
" #It prints a message if no keys have been collected and another message if keys have been collected.\n",
" #The difference between the print in the elif and else is just to make sure \n",
" #that the last two keys are separated by a word \"and\" instead of a comma.\n",
" \n",
" myList = []\n",
" for i in range(len(game_state[\"keys_collected\"])):\n",
" myList.append(game_state[\"keys_collected\"][i].get(\"name\"))\n",
" \n",
" if len(myList)==0:\n",
" print('You have nothing on your pocket.')\n",
" elif len(myList)==1:\n",
" print('In your pocked you find: ' + ''.join(myList) + '.')\n",
" else:\n",
" print('In your pocked you find: ' + \" and \".join([\", \".join(myList[:-1]),myList[-1]]) + '.')\n",
"\n",
"def are_words_similar(s1,s2):\n",
" \"\"\"\n",
" Compares the lower case version of two words.\n",
" Allows for words to have one typo.\n",
" \"\"\"\n",
" s1 = s1.strip().lower()\n",
" s2 = s2.strip().lower()\n",
" if len(s1) > len(s2):\n",
" s1,s2 = s2,s1\n",
" s = sum([s1[i] != s2[i] for i in range(len(s1))])\n",
" if s == 1:\n",
" return True\n",
" else:\n",
" return False\n",
"\n",
"def show_map():\n",
" if game_room in game_state[\"map_collected\"] and corridor not in game_state[\"map_collected\"]:\n",
" display(game_room[\"map\"])\n",
" time.sleep(0.1)\n",
" return\n",
" elif corridor in game_state[\"map_collected\"] and bathroom not in game_state[\"map_collected\"]:\n",
" display(game_room[\"map\"])\n",
" time.sleep(0.1)\n",
" return\n",
" elif bathroom in game_state[\"map_collected\"] and kitchen not in game_state[\"map_collected\"]:\n",
" display(bathroom[\"map\"])\n",
" time.sleep(0.1)\n",
" return\n",
" elif kitchen in game_state[\"map_collected\"] and living_room not in game_state[\"map_collected\"]:\n",
" display(kitchen[\"map\"])\n",
" time.sleep(0.1)\n",
" return\n",
" elif living_room in game_state[\"map_collected\"]:\n",
" display(living_room[\"map\"])\n",
" time.sleep(0.1)\n",
" return"
]
},
{
"cell_type": "code",
"execution_count": 73,
"metadata": {
"id": "55EMPCGHDvIO"
},
"outputs": [],
"source": [
"# Game Room.\n",
"# Bookshelf Interactions (Function)\n",
"\n",
"def consult_books(knows_russian):\n",
" if knows_russian == False:\n",
" print(\"You look at the bookshelf. You find the following books:\")\n",
" for book in (bookshelf.get(\"books_in_russian\")):\n",
" print(str(bookshelf.get(\"books_in_russian\").index(book)) + str(\" - \" + book))\n",
" elif knows_russian == True:\n",
" print(\"You go to the bookshelf, you find many books in russian. Their tittles in English are:\")\n",
" for book in (bookshelf.get(\"books_in_english\")):\n",
" print(str(bookshelf.get(\"books_in_english\").index(book)) + str(\" - \" + book))\n",
"\n",
"def take_book(): \n",
" print('Do you want to take a book? Write: ' + color.DARKCYAN + color.BOLD + \"Yes\" + color.END + \" or \"+ color.DARKCYAN + color.BOLD + \"No\" + color.END)\n",
" take_book_yes_no = input('').lower().strip()\n",
" if take_book_yes_no == \"no\":\n",
" return \"no\"\n",
" elif take_book_yes_no == \"yes\":\n",
" return \"yes\" \n",
"\n",
"def choose_book(knows_russian):\n",
" print('Which book do you want to take? Write the number which identifies the book')\n",
" book_chosen = input('').lower().strip()\n",
" if knows_russian == False:\n",
" if book_chosen == str(15):\n",
" print('A dictionary! It helps reading russian. ' + color.UNDERLINE + 'You feel like you learnt something today.' + color.END)\n",
" game_state[\"knowledge_collected\"].append(russian)\n",
" side_table[\"flavour_text\"] = \"A table with a picture of an old lady reading a book on top of it. She is devouring the book called \" + color.BOLD + \"The Jungle Book.\" + color.END\n",
" return str(book_chosen)\n",
" elif book_chosen == str(4):\n",
" print('You do not speak baguette. You wonder why do French always copy English words... croissant comes to mind.')\n",
" print('You put back the book.')\n",
" return str(book_chosen)\n",
" elif book_chosen in str([0, 1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16]) or book_chosen in [\"zero\", \"one\", \"two\", \"three\", \"five\", \"six\", \"seven\", \"eight\", \"nine\", \"ten\", \"eleven\", \"twelve\", \"thirteen\", \"fourteen\", \"sixteen\"]:\n",
" print('These characters are somewhat familiar, but you have no idea how to prounounce anything.')\n",
" print('You put back the book.')\n",
" return str(book_chosen)\n",
" else:\n",
" print('Input unclear.')\n",
" choose_book(knows_russian)\n",
" return\n",
" elif knows_russian == True:\n",
" if book_chosen == str(15):\n",
" print('A dictionary! It helps reading russian... which you already know!')\n",
" print('You put back the book.')\n",
" return str(book_chosen)\n",
" elif book_chosen == str(16):\n",
" if key_gameroom in game_state[\"keys_collected\"]:\n",
" print('Classic literature... boring.')\n",
" return str(book_chosen)\n",
" else:\n",
" print('You open The Jungle. You find a key inside! ' + color.UNDERLINE + 'You take it with you!' + color.END)\n",
" game_state[\"keys_collected\"].append(key_gameroom)\n",
" return str(book_chosen)\n",
" elif book_chosen in str([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) or book_chosen in [\"zero\", \"one\", \"two\", \"three\", \"four\", \"five\", \"six\", \"seven\", \"eight\", \"nine\", \"ten\", \"eleven\", \"twelve\", \"thirteen\", \"fourteen\"]:\n",
" print('Classic literature... boring.')\n",
" print('You put back the book.')\n",
" return str(book_chosen)\n",
" else:\n",
" print('Input unclear.')\n",
" choose_book(knows_russian)\n",
" return\n",
"\n",
"def play_bookshelf():\n",
" consult_books(russian in game_state[\"knowledge_collected\"])\n",
" if take_book() == \"yes\":\n",
" cycle_break = False\n",
" while not(cycle_break):\n",
" if choose_book(russian in game_state[\"knowledge_collected\"]) == \"15\" and not (russian in game_state[\"knowledge_collected\"]):\n",
" cycle_break = True\n",
" elif (russian in game_state[\"knowledge_collected\"]):\n",
" cycle_break = True\n",
" else:\n",
" return\n",
" \n",
"#The statement below adds the function above to the bookshelf dictionary/object.\n",
"bookshelf[\"play\"] = play_bookshelf"
]
},
{
"cell_type": "code",
"execution_count": 74,
"metadata": {
"id": "0mt-b6f_4d8S"
},
"outputs": [],
"source": [
"#Bathroom Functions, one per interactable furniture.\n",
"\n",
"def bathtub_check():\n",
" furniture = bathtub\n",
" have_tool = False\n",
" if (bathtub[\"counter\"] == 0):\n",
" play_my_sound(bathtub[\"sound\"])\n",
" print(\"You remove some of the waters, you see a comb floating. You do a minor attempt at uncloggin the bathtub.\")\n",
" print(\"A voice behind you says \" + color.BOLD + \"DEEPER\" + color.END + \" in a very sinister way.\")\n",
" bathtub[\"counter\"] +=1\n",
" play_room(game_state[\"current_room\"])\n",
" if (bathtub[\"counter\"] == 1):\n",
" play_my_sound(bathtub[\"sound\"])\n",
" print(\"You hear the same voice shouting \" + color.BOLD + \"I SAID DEEPER, BLYAT\" + color.END + \".\")\n",
" print(\"Better comply...\")\n",
" bathtub[\"counter\"] +=1\n",
" play_room(game_state[\"current_room\"])\n",
" if (bathtub[\"counter\"] == 2):\n",
" play_my_sound(bathtub[\"sound\"])\n",
" print(\"You are tired of of putting your arm elbow-deep into the pipes. Yet, within the cold water, you are able to find a cork stuck. \\n\"\n",
" \"After a few seconds you can take it off and drain the bathtub slowly. In the bottom you see what looks like a \" + color.UNDERLINE + \"toilet lever\" + color.END + \".\")\n",
" game_state[\"knowledge_collected\"].append(lever)\n",
" bathtub[\"useful\"] = False\n",
" play_room(game_state[\"current_room\"])\n",
"\n",
"def toilet_check():\n",
" furniture = toilet\n",
" have_tool = False\n",
" for tool in game_state[\"knowledge_collected\"]:\n",
" if(tool[\"target\"] == furniture):\n",
" have_tool = True\n",
" if(have_tool):\n",
" game_state[\"knowledge_collected\"].append(wrench)\n",
" print(\"You can work with the lever to flush it until midpoint. You see a shiny object and pick it up. It’s a \" + color.UNDERLINE + \"rusty steel wrench\" + color.END + \".\")\n",
" toilet[\"useful\"] = False\n",
" play_room(game_state[\"current_room\"])\n",
" else:\n",
" print(\"Eeeew. You can’t possibly get your arm onto that mess... the devs are not that mean.\")\n",
" play_room(game_state[\"current_room\"])\n",
" return None\n",
"\n",
"def sink_check():\n",
" furniture = sink\n",
" have_tool = False\n",
" for tool in game_state[\"knowledge_collected\"]:\n",
" if(tool[\"target\"] == furniture):\n",
" have_tool = True\n",
" if(have_tool):\n",
" print(\"You are a man of culture and go for the piping. You can easen some bolts until it falls apart and all water furiously drains down and something metallic shines and bounces to the rug.\")\n",
" sink[\"useful\"] = False\n",
" play_room(game_state[\"current_room\"])\n",
" else:\n",
" print(\"You put your right arm deep into the water and can’t unplug the thick substance. Looks like you could fix it by easing the water pipe.\")\n",
" play_room(game_state[\"current_room\"])\n",
"\n",
"def rug_check():\n",
" furniture = rug\n",
" if sink[\"useful\"] == False:\n",
" game_state[\"keys_collected\"].append(key_kitchen)\n",
" print(\"You pick the \"+ color.UNDERLINE + \"key\" + color.END + \" from the mushy floor that comes attached to a beer opener.\")\n",
" rug[\"useful\"] = False\n",
" play_room(game_state[\"current_room\"])\n",
" else:\n",
" print(\"Who the hell has a rug on a bathroom? I’ll keep looking somewhere else, maybe on the bathtub?\")\n",
" play_room(game_state[\"current_room\"])\n",
"\n",
"toilet[\"play\"] = toilet_check\n",
"sink[\"play\"] = sink_check\n",
"bathtub[\"play\"] = bathtub_check\n",
"rug[\"play\"] = rug_check"
]
},
{
"cell_type": "code",
"execution_count": 75,
"metadata": {
"id": "Fq827loV7cT-"
},
"outputs": [],
"source": [
"# KITCHEN\n",
"def open_cutlery_drawer():\n",
" have_wrench = False\n",
" if wrench in game_state[\"knowledge_collected\"]:\n",
" have_wrench = True\n",
" if (have_wrench == True):\n",
" play_my_sound(cutlery_drawer[\"sound\"])\n",
" print(\"You feel empowered enough to force the drawer and open it with the wrench. After the hit, you encounter something soft, yet crunchy. After inspection it was the putrid corpse of a rat that you moved and, below it, there is a \" + color.BOLD + \"wine opener.\" + color.END)\n",
" game_state[\"knowledge_collected\"].append(wine_opener)\n",
" cutlery_drawer[\"useful\"] = False\n",
" print(\"You have found a wine opener\")\n",
" play_room(game_state[\"current_room\"])\n",
" elif (wine_opener in game_state[\"knowledge_collected\"]):\n",
" print(\"There is just some old fashion cutlery.\")\n",
" else:\n",
" print(cutlery_drawer[\"flavour_text\"])\n",
" play_room(game_state[\"current_room\"])\n",
" return None\n",
"\n",
"def examine_pantry ():\n",
" print (pantry[\"flavour_text\"])\n",
" have_wine_opener = False\n",
" ### RUI'S COMMENT: We never talk about the exit command. I THINK IT WORKS DIFFERENTLY IN GOOGLE COLABORATIVE AND IN JUPYTER, SO I GUESS WE SHOULD REMOVE IT.\n",
" print(\"What would you like to examine? Type \" + (color.DARKCYAN + \" or \".join(pantry[\"object\"]) + color.END) + \". Type \\\"exit\\\" if you would like to go back to the kitchen.\")\n",
" to_examine = input()\n",
" if wine_opener in game_state[\"knowledge_collected\"]:\n",
" have_wine_opener = True\n",
" #### RUI'S COMMENT: I THINK THAT INSTEAD of to_examine == \"wine\" (or == \"food can\") we need \"old wines\" or \"food cans\" HERE !!!\n",
" if to_examine == \"wine\":\n",
" if have_wine_opener == False:\n",
" linebreak()\n",
" print(\"You pick a bottle and try the cork, but without the proper tool you can’t open it. On the tag you can read горули мцване 1890 so it’s been there for a while. The wine looks surprisingly well preserved.\")\n",
" print(\"Perhaps it was an important gift.\")\n",
" examine_pantry()\n",
" elif have_wine_opener == True:\n",
" linebreak()\n",
" print(\"Looks like a very Georgian wine. You imagine this is what rich people drink.\")\n",
" game_state[\"knowledge_collected\"].append(wine)\n",
" print(\"You have found \" + color.UNDERLINE + \"wine\" + color.END + \".\")\n",
" examine_pantry()\n",
" elif wine in game_state[\"knowledge_collected\"]:\n",
" linebreak()\n",
" print(\"Just some old fancy wines.\")\n",
" examine_pantry()\n",
" elif to_examine == \"food can\":\n",
" linebreak()\n",
" print (\"You take a can and see the tag has written Cрок годности 01-09-//////// on it. Looks like a date in which the year has faded over the time.\")\n",
" examine_pantry()\n",
" elif to_examine == \"exit\":\n",
" play_room(kitchen)\n",
" else:\n",
" print(\"Object not found. Try it again.\")\n",
" linebreak()\n",
" examine_pantry()\n",
" \n",
"\n",
"pantry[\"play\"] = examine_pantry\n",
"cutlery_drawer[\"play\"] = open_cutlery_drawer"
]
},
{
"cell_type": "code",
"execution_count": 76,
"metadata": {
"id": "utdxs7mvghUg"
},
"outputs": [],
"source": [
"#Living Room Functions\n",
"\n",
"def crib_check():\n",
" furniture = crib\n",
" print(\"You look into the crib. There is a one-eyed, bald baby doll and a mobile over it. You feel the doll follows your sight...\")\n",
" check = input(\"Want to check mobile or doll?\\n\").strip().lower()\n",
" if (check == \"doll\"):\n",
" print(\"You realize it is an old doll, without hair and with signs of violence, and it's looking to the mobile over it.\")\n",
" play_room(game_state[\"current_room\"])\n",
" if(check == \"mobile\"):\n",
" print(\"It is made of different wooden birds, and it starts playing a lullaby that makes the old woman wakes up and starts babling.\"\n",
" \"You feel nothing good will come from staying longer in this house\")\n",
" old_lady[\"status\"] = \"awaken\"\n",
" crib[\"useful\"] = False\n",
" play_room(game_state[\"current_room\"])\n",
" else:\n",
" print(\"Please enter either option given.\")\n",
" crib_check()\n",
"\n",
"def old_lady_check():\n",
" furniture = old_lady\n",
" have_hammer = False\n",
" if (old_lady[\"status\"] == \"sleeping\"):\n",
" print(\"She is a very old lady, wearing all black clothes and sitting on a wooden chair. You can't tell if she's asleep or dead but you'd better be carefull\")\n",
" play_room(game_state[\"current_room\"])\n",
" if (old_lady[\"status\"] == \"awaken\"):\n",
" if (wine in game_state[\"knowledge_collected\"]):\n",
" print(\"She wants the wine, do you want to open it for her? Go to the kitchen and use this hammer\")\n",
" if (wine_opener in game_state[\"knowledge_collected\"]):\n",
" old_lady[\"status\"] = \"drunk\"\n",
" game_state[\"knowledge_collected\"].append(keys_pendulum)\n",
" old_lady[\"useful\"] = False\n",
" play_my_sound(old_lady[\"sound\"])\n",
" print(\"She jumps and takes the bottle and the opener and proceeds to chug it. When doing so, a \" + color.UNDERLINE + \"set of small keys\" + color.END + \" fall from her lap to your hands.\")\n",
" else:\n",
" print(\"Maybe in the kitchen there's a tool to open it... The old woman salivates looking to the wine and shouts incohesive words to you, that most certainly aren’t compliments\")\n",
" else:\n",
" print(\"The old woman speaks in a broken voice but you can just recognise two word in russian that you learned in a pub a few years back. “wiii----ne p-----leeeeeeas---e\")\n",
" play_room(game_state[\"current_room\"])\n",
" else:\n",
" print(\"test\")\n",
" play_room(game_state[\"current_room\"])\n",
"\n",
"def pendulum_check():\n",
" furniture = pendulum\n",
" if (pendulum[\"status\"] == \"closed\"):\n",
" print(\"The pendulum clock is set at 9:15 AM, but it's stopped. you see yet another 4 digit locker on the door to access it.\")\n",
" print(\"Sigh... you wish there were password hints here. Everyone puts their codes on those.\")\n",
" try_password = input(\"Enter the 4 digit combination\").strip()\n",
" if (furniture[\"code\"] == try_password):\n",
" pendulum[\"status\"] = \"open\"\n",
" print(\"The lock opens but there is another issue...\")\n",
" if (try_password == \"exit\"):\n",
" play_room(game_state[\"current_room\"])\n",
" if(furniture[\"code\"] != try_password):\n",
" print('\"Wrong password.\" You try again')\n",
" pendulum_check()\n",
" if (pendulum[\"status\"] == \"open\"):\n",
" if (keys_pendulum in game_state[\"knowledge_collected\"]):\n",
" pendulum[\"useful\"] = False\n",
" print(\"You find a small paper \" + color.UNDERLINE + \"The last digit is 7\" + color.END + \"looks like some musical code\")\n",
" else:\n",
" print(\"There is a smaller box inside that could be opened with a set of keys\")\n",
" play_room(game_state[\"current_room\"])\n",
" else:\n",
" print(\"What a gorgeous clock this must have been.\")\n",
" play_room(game_state[\"current_room\"])\n",
"\n",
"crib[\"play\"] = crib_check\n",
"old_lady[\"play\"] = old_lady_check\n",
"pendulum[\"play\"] = pendulum_check\n"
]
},
{
"cell_type": "code",
"execution_count": 77,
"metadata": {
"id": "7TC2r1MyIMyE"
},
"outputs": [],
"source": [
"def piano_check():\n",
" furniture = piano\n",
" print(\"The piano there is a 4 digit locker on the lid. Pianos don't have lockers unless they have something inside that you want.\")\n",
" try_password = input(\"Enter the 4 digit combination\").strip()\n",
" if (piano[\"code\"] == try_password):\n",
" piano[\"useful\"] = False\n",
" game_state[\"keys_collected\"].append(key_outside)\n",
" print(\"It is open!\")\n",
" if (try_password == \"exit\"):\n",
" return\n",
" if (furniture[\"code\"] != try_password):\n",
" print('\"Wrong password.\" You try again')\n",
" piano_check()"
]
},
{
"cell_type": "code",
"execution_count": 78,
"metadata": {
"id": "IkA-BsKlWKzD"
},
"outputs": [],
"source": [
"# Enter password \n",
"def enter_password(item):\n",
" print((\"The \" + item[\"name\"] + \" has a password! Enter the password or type \\\"exit\\\" to go back to room\"))\n",
" try_password = input().strip().lower()\n",
" output = \"\"\n",
" if (item[\"password\"] == try_password):\n",
" output = \"Correct password!\"\n",
" linebreak()\n",
" if(item[\"name\"] in object_relations and len(object_relations[item[\"name\"]])>0):\n",
" item_found = object_relations[item[\"name\"]].pop()\n",
" game_state[\"keys_collected\"].append(item_found)\n",
" output = \"You find \" + item_found[\"name\"] + \".\"\n",
" print (output)\n",
" elif (try_password == \"exit\"):\n",
" play_room(game_state[\"current_room\"])\n",
" else:\n",
" output += \"Wrong password.\"\n",
" print (output)\n",
" enter_password(item)\n",
"\n",
"vault[\"play\"] = enter_password\n",
"stove_oven[\"play\"] = enter_password\n",
"piano[\"play\"] = enter_password"
]
},
{
"cell_type": "code",
"execution_count": 79,
"metadata": {
"id": "WhuLmtzySq2e"
},
"outputs": [],
"source": [
"# Here is where the \"main\" cycles are.\n",
"def start_game():\n",
" #Resetting variables which are changed throughout code execution.\n",
" side_table[\"flavour_text\"] = \"A table with a picture of an old lady reading a book on top of it. She is devouring the book called \" + color.BOLD + \"книга джунглей.\" + color.END\n",
" print(\"You wake up on a couch and find yourself in a strange house with no windows which you have never been to before.\")\n",
" print(\"You don't remember why you are here and what had happened before. You feel some unknown danger is approaching and you must get out of the house, NOW!\")\n",
" play_room(game_state[\"current_room\"])\n",
"\n",
"def play_room(room):\n",
" \"\"\"\n",
" Play a room. First check if the room being played is the target room.\n",
" If it is, the game will end with success. Otherwise, let player either \n",
" explore (list all items in this room) or examine an item found here.\n",
" \"\"\"\n",
" game_state[\"current_room\"] = room\n",
" if(game_state[\"current_room\"] == game_state[\"target_room\"]):\n",
" #play_my_sound(sound_victory)\n",
" print(color.GREEN + color.BOLD + \"Congrats! You escaped the room!\" + color.END)\n",
" else:\n",
" print(\"You are now in \" + room[\"name\"])\n",
" print(\"What would you like to do? Type 'explore' or 'examine'? \\n\")\n",
" intended_action = input(\"\").strip().lower()\n",
" if intended_action == \"explore\": ### Here we should use the are_words_similar(s1,s2) function instead.\n",
" explore_room(room)\n",
" print(\"\\n\")\n",
" play_room(room)\n",
" elif intended_action == \"examine\": ### Here we should use the are_words_similar(s1,s2) function instead.\n",
" print(\"What would you like to examine?\")\n",
" use_item_choice = input(\"\").strip().lower()\n",
" \n",
" if examine_silent(use_item_choice) != None:\n",
" room = examine_item(use_item_choice)\n",
" print(\"\\n\")\n",
" play_room(room)\n",
" else:\n",
" print(\"\\n\")\n",
" play_room(room)\n",
" elif intended_action == \"exit\": ### Here we should use the are_words_similar(s1,s2) function instead.\n",
" quit(keep_kernel=True)\n",
" else:\n",
" print(\"Not sure what you mean. Type 'explore' or 'examine'.\")\n",
" play_room(room)\n",
" print(\"\\n\")\n",
"\n",
"def explore_room(room):\n",
" \"\"\"Explore a room. List all items belonging to this room.\"\"\"\n",
" items = [i[\"name\"] for i in object_relations[room[\"name\"]]]\n",
" print(\"You explore the room. This is \" + room[\"name\"] + \". You find \" + \", \".join(items))\n",
" keys_in_pocket()\n",
" print(\"You scrapped some notes about the layout of the house. Do you want to see them? Write: \" + color.DARKCYAN + color.BOLD + \"Yes\" + color.END + \" or \"+ color.DARKCYAN + color.BOLD + \"No\" + color.END)\n",
" yes_no_show_map = input().strip().lower()\n",
" if yes_no_show_map == \"yes\":\n",
" show_map()\n",
" return\n",
" elif yes_no_show_map == \"no\":\n",
" return\n",
" else:\n",
" print(\"Not sure what you mean...\")\n",
" explore_room(room)\n",
"\n",
"def get_next_room_of_door(door, current_room):\n",
" \"\"\"From object_relations, find the two rooms connected to the given door. Return the room that is not the current_room.\"\"\"\n",
" connected_rooms = object_relations[door[\"name\"]]\n",
" play_my_sound(sound_door_creaking)\n",
" for room in connected_rooms:\n",
" if(not current_room == room):\n",
" return room\n",
"\n",
"# Function to examine item. Similar to that of the original project.\n",
"def examine_item(item_name):\n",
" \n",
" room = game_state[\"current_room\"]\n",
" \n",
" #### RUI: I THINK THAT THE REASON WHY THE \"Thanks to the key, you move on to the next room.\" APPEARS TWICE IS.\n",
" #### BECAUSE THIS LOOP ALWAYS LOOPS THROUGH THE TWO ITEMS THAT ARE IN EACH OF THE OBJECT RELATIONS OF EACH ROOM.\n",
" #### NOT SURE HOW TO FIX IT THOUGH.\n",
" \n",
" for item in object_relations[room[\"name\"]]:\n",
" if(item[\"name\"] == item_name):\n",
" #The if below governs what happens if we are not interaction with a door.\n",
" if item[\"type\"] != \"door\": \n",
" output = \"You examine \" + item_name + \":\"\n",
" # ... if the item is not useful we just throw in the flavour text\n",
" # \n",
" if(item[\"useful\"] == False):\n",
" print(item[\"flavour_text\"])\n",
" return None\n",
" play_room(room)\n",
" # ... if it is useful we throw in the function which is stored in the key \"play\" of the object.\n",
" elif (item[\"useful\"] == True):\n",
" if (\"password\" in item):\n",
" print(item[\"flavour_text\"])\n",
" item.get(\"play\")(item)\n",
" elif (\"password\" not in item):\n",
" item.get(\"play\")()\n",
" return None\n",
" # if it is a door, we have the same interaction as in the sample (to open it).\n",
" elif (item[\"type\"] == \"door\"):\n",
" have_key = False\n",
" for key in game_state[\"keys_collected\"]:\n",
" if(key[\"target\"] == item):\n",
" have_key = True\n",
" if(have_key):\n",
" print(\"Thanks to the key, you move on to the next room. The door slowly shuts itself behind you.\")\n",
" next_room = get_next_room_of_door(item, room)\n",
" game_state[\"map_collected\"].append(next_room)\n",
" return next_room\n",
" else:\n",
" print(\"It is locked but you don't have the key.\")\n",
" return None\n",
" #else: return\n",
"\n",
"def examine_silent(item_name):\n",
" \n",
" room = game_state[\"current_room\"]\n",
" for item in object_relations[room[\"name\"]]:\n",
" if(item[\"name\"] == item_name):\n",
" #The if below governs what happens if we are not interaction with a door.\n",
" if item[\"type\"] != \"door\": \n",
" output = \"You examine \" + item_name + \":\"\n",
" # ... if the item is not useful we just throw in the flavour text\n",
" # \n",
" if(item[\"useful\"] == False):\n",
" print(item[\"flavour_text\"])\n",