-
Notifications
You must be signed in to change notification settings - Fork 0
/
classes.py
876 lines (713 loc) · 29.2 KB
/
classes.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
from sys import exit
from random import randint
def exit_bad_selection():
print "Error: you should not have got to this point."
print "Our apologies, please restart the story."
exit(1)
def code_generation(victim):
code_map = {
"a": "2",
"b": "2",
"c": "2",
"d": "3",
"e": "3",
"f": "3",
"g": "4",
"h": "4",
"i": "4",
"j": "5",
"k": "5",
"l": "5",
"m": "6",
"n": "6",
"o": "6",
"p": "7",
"q": "7",
"r": "7",
"s": "7",
"t": "8",
"u": "8",
"v": "8",
"w": "9",
"x": "9",
"y": "9",
"z": "9",
}
code = ""
for char in victim:
val = code_map.get(char.lower())
code += (val)
return str(code)
class Victim(object):
names = [
"Anna",
"Beth",
"Cass",
"Dana",
"Erin",
"Faye",
"Gwen",
"Hope",
"Indy",
"Juno",
"Kate",
"Lily",
"Mona",
"Nina",
"Olga",
"Posy",
"Rose",
"Sara",
"Thea",
"Vera",
"Wada",
"Yuna",
"Zola",
]
def __init__(self):
self.name = self.names[randint(0, len(self.names) - 1)]
self.code = code_generation(self.name)
girl = Victim()
class Scene(object):
def __init__(self):
self.VISITS = 0
def enter(self):
print "This scene is not yet configured. Subclass it and implement ",
print "enter()."
exit(1)
def show_hints(self, hints):
print "="*10
for line in hints:
print line
print "="*10
class Engine(object):
def __init__(self, scene_map):
self.scene_map = scene_map
def play(self):
current_scene = self.scene_map.opening_scene()
last_scene = self.scene_map.next_scene('finished')
while current_scene != last_scene:
next_scene_name = current_scene.enter()
current_scene = self.scene_map.next_scene(next_scene_name)
current_scene.enter()
class Opening(Scene):
def enter(self):
print "#"*50
print 'Operator: "Operator, what\'s your emergency?"'
print 'Caller: "I\'ve seen someone acting suspcious up at the old '
print '\tfarm house..."'
print "#"*50
print "\nYou, a local detective, arrive at the house the caller "
print "described. Set back off the road, tree lined on all sides of "
print "the grounds sits an old farm house that has seen better days."
print "There is land around the house with farmland beyond the border."
print "The house has a large front porch, paint peeling from its "
print "balustrade. The investigation begins...\n\n"
return 'outside'
class Outside(Scene):
hints = [
"walk to the porch",
"search the garden",
]
def enter(self):
if self.VISITS == 0:
print "You look around at the overgrown gardens surrounding the "
print "house. It looks like nobody has tended to them for a long"
print "time. Grass comes to the waist with wild weeds throughout."
print "A dusty track leads up to the porch."
print "\n\n*** Note: type 'hint' at any point to see ***"
print "*** acceptable actions. ***"
else:
pass
self.VISITS += 1
while True:
choice = raw_input("> ").lower()
if choice == "hint" or choice == "hints":
self.show_hints(self.hints)
continue
elif choice in self.hints:
if choice == "walk to the porch":
return 'porch'
elif choice == "search the garden":
print "You search the gardens around the house and find"
print "nothing out of the ordinary."
self.hints.remove("search the garden")
continue
else:
exit_bad_selection()
else:
print "That option is not valid here."
continue
class Porch(Scene):
hints = [
"enter the house",
]
def enter(self):
if self.VISITS == 0:
print "The steps creak as you walk up them. A fine film of dust"
print "covers every surface. The porch light casing is broken and"
print "discoloured. The door is open..."
else:
print "You step onto the porch."
self.VISITS += 1
while True:
choice = raw_input("> ").lower()
if choice == "hint" or choice == "hints":
self.show_hints(self.hints)
continue
elif choice in self.hints:
if choice == "enter the house":
print "You walk through the door, into the hallway."
return 'hallway'
else:
exit_bad_selection
else:
print "That option is not valid here."
continue
class Hallway(Scene):
hints = [
"look in the cupboard",
"go to the reception",
"go to the dining room",
"go upstairs",
]
def enter(self):
if self.VISITS == 0:
print "A stale smell hangs in the air. It's clear that the house"
print "does not have many visitors. To the left is a reception"
print "area, to the right a dining room. In front of you is a"
print "cupboard with a staircase starting on the right with a left"
print "turn half way up that would take you to the landing."
else:
pass
self.VISITS += 1
while True:
choice = raw_input("> ").lower()
if choice == "hint" or choice == "hints":
self.show_hints(self.hints)
continue
elif choice in self.hints:
if choice == "look in the cupboard":
print "The cupboard door sticks as you try to open it."
print "There is nothing inside except some old news papers"
print "covering the floor. You close the door again."
self.hints.remove("look in the cupboard")
continue
elif choice == "go to the reception":
return 'reception'
elif choice == "go to the dining room":
return 'dining_room'
elif choice == "go upstairs":
print "You walk up the stairs and onto the landing."
return 'landing'
else:
exit_bad_selection
else:
print "That option is not valid here."
continue
class Reception(Scene):
hints = [
"go to the lounge",
"go to the hallway",
"inspect the fireplace",
]
def enter(self):
print "You walk into the reception room."
if self.VISITS == 0:
print "Cobwebs are in every corner. Thick dust covers the mantle"
print "around the fireplace. The furniture is old and worn. The"
print "fireplace looks like it has not been used in some time."
self.VISITS += 1
while True:
choice = raw_input("> ").lower()
if choice == "hint" or choice == "hints":
self.show_hints(self.hints)
continue
elif choice in self.hints:
if choice == "inspect the fireplace":
print "You crouch in front of the fireplace to get a"
print "closer look at the ash. This fire was a long time"
print "ago and it looks like someone was burning more than"
print "just logs! You think you can see signs of burned"
print "clothing. What has happened here?"
self.hints.remove("inspect the fireplace")
continue
elif choice == "go to the lounge":
return 'lounge'
elif choice == "go to the hallway":
print "You walk into the hallway."
return 'hallway'
else:
exit_bad_selection
else:
print "That option is not valid here."
continue
class Lounge(Scene):
hints = [
"go to the kitchen",
"go to the reception",
]
def enter(self):
print "You walk into the lounge."
if self.VISITS == 0:
print "The first thing you notice as you walk into the lounge is"
print "that there is a back door that has been nailed shut with"
print "timbers. Dust clings to all surfaces. It's clear no one"
print "has been using this room."
self.VISITS += 1
while True:
choice = raw_input("> ").lower()
if choice == "hint" or choice == "hints":
self.show_hints(self.hints)
continue
elif choice in self.hints:
if choice == "go to the kitchen":
return 'kitchen'
elif choice == "go to the reception":
return 'reception'
else:
exit_bad_selection
else:
print "That option is not valid here."
continue
class Kitchen(Scene):
hints = [
"go to the dining room",
"go to the lounge",
]
def enter(self):
print "You walk into the kitchen."
if self.VISITS == 0:
print "This kitchen has not been used in some time, and not"
print "cleaned even longer still. The fridge has been turned off,"
print "there's no crockery to be found and a putrid smell rises"
print "from the sink drain."
self.VISITS += 1
while True:
choice = raw_input("> ").lower()
if choice == "hint" or choice == "hints":
self.show_hints(self.hints)
continue
elif choice in self.hints:
if choice == "go to the dining room":
return 'dining_room'
elif choice == "go to the lounge":
return 'lounge'
else:
exit_bad_selection
else:
print "That option is not valid here."
continue
class DiningRoom(Scene):
hints = [
"go to the kitchen",
"go to the hallway",
]
def enter(self):
print "You walk into the dining room."
if self.VISITS == 0:
print "The dining table that would have once stood central in the"
print "room has been tipped on one end and stood in front of the"
print "window. Someone did not want people looking in too closely."
print "The chairs are pushed to the outside of the room, and a"
print "large, worn out rug lays on the floor in the centre of the"
print "room."
self.VISITS += 1
while True:
choice = raw_input("> ").lower()
if choice == "hint" or choice == "hints":
self.show_hints(self.hints)
continue
elif choice in self.hints:
if choice == "go to the kitchen":
return 'kitchen'
elif choice == "go to the hallway":
print "You walk into the hallway."
return 'hallway'
else:
exit_bad_selection
else:
print "That option is not valid here."
continue
class Landing(Scene):
hints = [
"examine the landing area more closely",
"go to the back room",
"go to the front left room",
"go to the front right room",
"go to the back right room",
"go to the back left room",
"go downstairs",
]
def enter(self):
if self.VISITS == 0:
print "The stairs were bare, their varnish worn over the years."
print "The landing is windowed to the front of the house, walls"
print "make up the other three sides, with one door on the back"
print "wall and two doors each on the left and right. The front"
print "window has tattered old curtains still hanging from a bowed"
print "rail, the weight starting to pull the fixings out of the"
print "wall."
self.VISITS += 1
while True:
choice = raw_input("> ").lower()
if choice == "hint" or choice == "hints":
self.show_hints(self.hints)
continue
elif choice in self.hints:
if choice == "examine the landing area more closely":
print "Something seems off about the landing..."
print "Your eyes dart around the scene, looking between"
print "the window... the doors... the railings around the"
print "stairs... the ceiling...\n"
print "... the ceiling... that's strange. Why is there no"
print "hatch to the loft?"
self.hints.remove("examine the landing area more closely")
continue
elif choice == "go to the back room" or \
choice == "go to the bathroom":
try:
self.hints.remove("go to the back room")
self.hints.append("go to the bathroom")
finally:
return 'bathroom'
elif choice == "go to the front left room" or \
choice == "go to the front left bedroom":
try:
self.hints.remove("go to the front left room")
self.hints.append("go to the front left bedroom")
finally:
return 'bedroom_1'
elif choice == "go to the back left room" or \
choice == "go to the back left bedroom":
try:
print "You walk into the main bedroom."
self.hints.remove("go to the back left room")
self.hints.append("go to the back left bedroom")
finally:
return 'bedroom_2'
elif choice == "go to the back right room":
return 'bedroom_3'
elif choice == "go to the front right room" or \
choice == "go to the front right bedroom":
try:
self.hints.remove("go to the front right room")
self.hints.append("go to the front right bedroom")
finally:
return 'bedroom_4'
elif choice == "go downstairs":
return 'hallway'
else:
exit_bad_selection
else:
print "That option is not valid here."
continue
class Bedroom1(Scene):
hints = [
"go to the landing",
]
def enter(self):
if self.VISITS == 0:
print "You walk into a small single bedroom, all of the furniture"
print "has been removed, discolouration on the walls where"
print "pictures used to hang. It was probably a child's room."
else:
print "You walk into the small single bedroom."
self.VISITS += 1
while True:
choice = raw_input("> ").lower()
if choice == "hint" or choice == "hints":
self.show_hints(self.hints)
continue
elif choice in self.hints:
if choice == "go to the landing":
print "You leave the room and walk back onto the landing"
return 'landing'
else:
exit_bad_selection
else:
print "That option is not valid here."
continue
class Bedroom2(Scene):
hints = [
"inspect the nightstand",
"inspect the dresser",
"go to the landing",
]
def __init__(self):
self.VISITS = 0
Bedroom2.KEY = 0
self.ATTEMPTS = 0
def enter(self):
if self.VISITS == 0:
print "You walk into a large bedroom, the size of which feels off"
print "for some reason. This room still has furniture. A large"
print "dresser on the opposite wall in the left corner. To the"
print "right under the window is a double bed with a nightstand on"
print "one side. The walls in this room are wood panelled."
else:
pass
self.VISITS += 1
while True:
choice = raw_input("> ").lower()
if choice == "hint" or choice == "hints":
self.show_hints(self.hints)
continue
elif choice in self.hints:
if choice == "inspect the nightstand":
print "The nightstand has a drawer at the top and shelf"
print "space underneath. The shelf holds a couple of crime"
print "novels, covers and corners well thumbed. You open"
print "the drawer and find sleeping tablets and a matchbox"
print "with an old logo on it. You have not seen that logo"
print "in some time so you decide to pick up the matchbox."
print "You shake it and something with some weight moves"
print "around inside... you slide the matchbox open and"
print "find a key."
if Bedroom3.DOOR_TRIES >= 1:
print "Maybe this is for that locked door?"
else:
print "You put the key in your pocket."
Bedroom2.KEY = 1
self.hints.remove("inspect the nightstand")
pass
elif choice == "inspect the dresser":
print "You look over the dresser and you can see the dust"
print "has been disturbed. You try to pull open a stiff"
print "drawer but the whole dresser slides. You look down"
print "at the legs and find they are sat on furniture"
print "gliders. Why would you want to move a dresser that"
print "much?"
self.hints.remove("inspect the dresser")
self.hints.append("move the dresser")
continue
elif choice == "move the dresser":
print "You slide the dresser away from the wall where you"
print "then find the wood panelling has been cut away to"
print "reveal a short door that comes up to waist"
print "height. The wood looks thick and heavy, and it is"
print "locked with a number pad."
self.hints.remove("move the dresser")
self.hints.append("try the number pad")
continue
elif choice == "try the number pad":
print "You crouch in front of the door and look at the"
print "number pad."
if self.ATTEMPTS == 0:
print "You recognise the type of lock, it should be a"
print "%d digit code." % len(girl.code)
print "*** NOTE: Enter C to go back to the room ***"
while True:
if self.ATTEMPTS >= 5 and self.ATTEMPTS % 5 == 0:
if Bedroom3.NAME_KNOWN == 1:
print "You need to keep going for %s!" \
% girl.name
print "What if her captor used her name as ",
print "the code?"
if self.ATTEMPTS >= 10:
print "*** HINT ***"
print "============="
print " 1 2 3 "
print " ABC DEF "
print " 4 5 6 "
print " GHI JKL MNO "
print " 7 8 9 "
print "PQRS TUV WXYZ"
print "============="
else:
print "Maybe there is a clue in the house?"
else:
pass
digits = raw_input("# ")
if digits == girl.code:
print "The lock clicks as you punch in the"
print "code and you cautiously push the heavy"
print "door open, revealing a staircase."
return 'loft'
elif digits == "C" or digits == "c":
print "You leave the lock and turn your"
print "attention back to the room."
return 'bedroom_2'
elif not digits:
continue
else:
print "That was not the code, try again."
self.ATTEMPTS += 1
continue
elif choice == "go to the landing":
print "You leave the room and walk back onto the landing"
return 'landing'
else:
exit_bad_selection
else:
print "That option is not valid here."
continue
class Bedroom3(Scene):
hints = [
"go to the landing",
]
def __init__(self):
self.VISITS = 0
Bedroom3.DOOR_TRIES = 0
Bedroom3.NAME_KNOWN = 0
def enter(self):
if Bedroom2.KEY == 0:
print "The door to this room is locked."
Bedroom3.DOOR_TRIES = 1
return 'landing'
elif Bedroom2.KEY == 1:
print "You take the key that you found and put it in the door."
print "The lock clicks, you turn the handle, and open the door."
Bedroom3.DOOR_TRIES = 2
else:
pass
if self.VISITS == 0:
print "You could not have imagined that this would be the scene."
print "The walls are covered in newspaper clippings and"
print "photographs. The articles are about a girl who disappeared"
print "ten years ago, not long after you had joined the force. She"
print "went missing outside of her home, no one had seen her"
print "since."
print "Her name was %s." % girl.name
print "The photographs... they are of her... most around the age"
print "she was when she went missing but some... some of them are"
print "of her older than that... and one of them... one of them"
print "was taken outside this house. What else are you going to"
print "find here? Was she held here? Is she still here?"
Bedroom3.NAME_KNOWN = 1
else:
print "You return to the large bedroom with all of the clippings."
self.VISITS += 1
while True:
choice = raw_input("> ").lower()
if choice == "hint" or choice == "hints":
self.show_hints(self.hints)
continue
elif choice in self.hints:
if choice == "go to the landing":
print "You leave the room and walk back onto the landing"
return 'landing'
else:
exit_bad_selection
else:
print "That option is not valid here."
continue
class Bedroom4(Scene):
hints = [
"go to the landing",
]
def enter(self):
if self.VISITS == 0:
print "Walking into a bedroom at the front right of the house you"
print "again find no furnishings. A slight crack in the window has"
print "made this room feel much colder than the rest of the house."
print "You gaze around but see nothing of interest."
else:
print "You walk into the bedroom at the front right of the house."
self.VISITS += 1
while True:
choice = raw_input("> ").lower()
if choice == "hint" or choice == "hints":
self.show_hints(self.hints)
continue
elif choice in self.hints:
if choice == "go to the landing":
print "You leave the room and walk back onto the landing"
return 'landing'
else:
exit_bad_selection
else:
print "That option is not valid here."
continue
class Bathroom(Scene):
hints = [
"go to the landing",
]
def enter(self):
if self.VISITS == 0:
print "You walk into a bathroom, dark and damp, the window has"
print "been covered with black bags to block the light coming in."
print "Although the rest of the house looks like it has been"
print "untouched for some time, this room looks like it's been"
print "used much more recently. There's a toothbrush in a glass by"
print "the sink, and signs of moisture in the bath as if someone"
print "has showered here recently..."
else:
print "You walk into the bathroom. There's nothing more to see"
print "here."
self.VISITS += 1
while True:
choice = raw_input("> ").lower()
if choice == "hint" or choice == "hints":
self.show_hints(self.hints)
continue
elif choice in self.hints:
if choice == "go to the landing":
print "You leave the room and walk back onto the landing"
return 'landing'
else:
exit_bad_selection
else:
print "That option is not valid here."
continue
class Loft(Scene):
def enter(self):
if Bedroom3.NAME_KNOWN == 1:
print "You rush up the stairs and into a fresh, clean, well"
else:
print "You ease up the stairs and into a fresh, clean, well"
print "decorated room that stands in stark contrast to the rest of"
print "the house you just came through."
print "You look around the room, there are no windows but lots of"
print "lamps and fairy lights flood your eyes with light that you"
print "need to adjust to after the dimness of the rooms below."
print "In the corner you spot a bed covered with blankets. The"
print "slightest of movement of the covers rising and falling tells"
print "you that someone is under them."
if Bedroom3.NAME_KNOWN == 1:
print "Your heart races, is she still here? Still alive?"
print 'You shout, "%s", and rush to the bed' % girl.name.upper()
print "It's her, you're sure of it. You try to wake her."
else:
print "Is someone being kept here? Who is it?"
print "You stride over to the bed."
print "You find a teenage girl lying in the bed, barely breathing."
print "You try to rock her awake and start checking her vitals."
print "\n\nYou do not notice that the wardrobe behind you has opened."
print "You do not notice that a man has stepped out of it."
print "You do notice though when he cocks his gun. You wheel around"
print "and find it levelled at your chest.\n\n"
print 'The Man: "Help her. Or you\'ll both be dead."'
return 'finished'
class Finished(Scene):
def enter(self):
print "=" * 40
print "Thank you for playing along with this interactive story."
print "=" * 40
exit(0)
class Map(object):
scenes = {
'opening': Opening(),
'outside': Outside(),
'porch': Porch(),
'hallway': Hallway(),
'reception': Reception(),
'lounge': Lounge(),
'kitchen': Kitchen(),
'dining_room': DiningRoom(),
'landing': Landing(),
'bedroom_1': Bedroom1(),
'bedroom_2': Bedroom2(),
'bedroom_3': Bedroom3(),
'bedroom_4': Bedroom4(),
'bathroom': Bathroom(),
'loft': Loft(),
'finished': Finished(),
}
def __init__(self, start_scene):
self.start_scene = start_scene
def next_scene(self, scene_name):
val = Map.scenes.get(scene_name)
return val
def opening_scene(self):
return self.next_scene(self.start_scene)