-
Notifications
You must be signed in to change notification settings - Fork 1
/
game.py
664 lines (512 loc) · 14.9 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
from sys import exit
import random
from random import randint
from content import *
from engine import *
from questions import *
class Scene(object):
# initialises each instance of Scene
def __init__(self):
self.name = None
self.description = None
self.visit = 0
def enter(self):
exit(1)
def user_input(self):
choice = raw_input(prompt)
lowercase = choice.lower()
key_words = lowercase.split(' ')
return key_words
def action(self):
pass
class Death(Scene):
scoffs = [
"Sorry! Try again soon :)",
"Oh no! Better luck next time :)",
"Nevermind! Tomorrow is another day :)"
]
def enter(self):
print Death.scoffs[randint(0, len(self.scoffs)-1)]
exit(1)
# Pre-game greeting scene where the players name is established.
class Greeting(Scene):
def enter(self):
name = raw_input("What's your name? ")
split = name.split(' ')
first = split.pop(0)
print "May I call you %s?" % first
confirm = raw_input(prompt)
global title
if confirm.lower() in affirm:
title = first
print "Great. Good to meet you %s" % first
elif confirm.lower() in negate:
title = raw_input("What shall we call you then? ")
print "Cool. Lovely to meet you %s" % title
else:
print "Sorry, I don't understand. Let's just call you Buddy"
title = 'Buddy'
def action(self):
return 'wake_room'
# First scene - player wakes in a strange room and has to choose between a tunnel or shaft.
class WakeRoom(Scene):
def enter(self):
if self.visit == 0:
print wake_room_intro
self.visit += 1
else:
print "What'll it be, tunnel or ventilation shaft?"
def action(self):
key_words = Scene.user_input(self)
for i in key_words:
if i in theWheelRoom:
return 'wheel_room'
elif i in pixieRoom:
return 'pixie'
print nonono + title + "."
return 'wake_room'
# Room with spinning wheel and 3 further doors.
class WheelRoom(Scene):
def enter(self):
print """
OK %s, you head through the tunnel, gagging at the rancid smell and
desperately trying to avoid the rusty, jagged metal protruding from the
walls. You reach a grate at the far end. It takes multiple kicks to
break it down, but finally it flies off and you climb down into a large
room.\n
In it you find three doors and a spinning wheel divided into thirds.
Next to it, a message reads:
""" % title
print message
def action(self):
key_words = Scene.user_input(self)
for i in key_words:
if i in affirm or i in spin:
number = random.randint(0,7)
print spin_text
if int(number) in range(0,3):
return 'child'
elif int(number) in range(3,6):
return 'space_time'
else:
print wrong_way
return 'wake_room'
elif i in negate:
return 'death'
print nonono + title + "."
return WheelRoom.action(self)
# Room with child who holds a bottle and a key for you to choose between.
class Child(Scene):
def enter(self):
print child_room_intro
print "Hello %s, I hope you've had a pleasant journey so far. In one hand I hold the key to your salvation, in the other, your doom. I wish I could tell you which was which, but only you can decide your fate." % title
def action(self):
key_words = Scene.user_input(self)
for i in key_words:
if i in child_bottle:
print bottle_text
return Child.either_door(self)
elif i.lower() in child_key:
print key_text
return 'death'
print nonono + title + "."
return Child.action(self)
def either_door(self):
key_words = Scene.user_input(self)
for i in key_words:
if i == 'east':
print "Looks like we're off to see the Wizard, %s!" % title
return 'wizard'
elif i == 'west':
print "Let's hope there's still some fight left in you, %s" % title
return 'ninja'
print nonono + title + "."
return Child.either_door(self)
# Room with teleportation device and time machine.
class SpaceTime(Scene):
def enter(self):
print space_time_intro
def action(self):
key_words = Scene.user_input(self)
for i in key_words:
if i in time_machine:
return 'historian'
elif i in teleportation:
print "Dammit. The stupid thing teleports you back to the start!"
return 'wake_room'
print nonono + title + "."
return SpaceTime.action(self)
# Walled garden with sleeping pixie.
class Pixie(Scene):
def enter(self):
if self.visit == 0:
print pixie_intro
self.visit = 1
else:
print pixie_intro_mini
# pixy_woken = False
def action(self):
key_words = Scene.user_input(self)
for i in key_words:
if i in pixieCross1:
print "Woah, big mistake %s. Never touch a sleeping pixie. For that matter, never approach any sleeping stranger and start touching them. That's just bad manners." % title
return 'death'
elif i in pixieHappy1:
print "She wakes up. Do you make polite chitchat or just get straight down to business?"
key_words = Scene.user_input(self)
for i in key_words:
if i in pixieCross2:
print "Nooo! Haven't you ever heard the saying, \"Never make small-talk with a pixy? They HATE it.\""
return 'death'
elif i in pixieHappy2:
print "Good. Pixies appreciate brevity. She unlocks the door for you."
return 'empty_room'
print "What? Bored with your nonesense, she falls back to sleep."
print "Let's try this again...whisper in her ear or tap her on the shoulder?"
return Pixie.action(self)
print nonono + title + "."
return Pixie.action(self)
# Wizard/Sorcerer who presents you with a riddle
class Wizard(Scene):
def enter(self):
print wizard_intro
def action(self):
key_words = Scene.user_input(self)
for i in key_words:
if i in affirm:
print "A wise decision %s" % title
return 'riddle'
elif i in negate:
print "Furious at your insubordination, she turns you into a coffee table anyway"
return 'death'
print nonono + title + "."
return Wizard.action(self)
# Riddle of the 3 people and 5 hats.
class Riddle(Scene):
def enter(self):
print riddle_text
def action(self):
choice = raw_input(prompt)
lowercase = choice.lower()
if "purple" and "red" in lowercase:
print "That's cheating. You get one guess"
return Riddle.action(self)
elif "purple" in lowercase:
print "Yay! The sorcerer applauds you on your riddle mastery and sends you on your way."
return 'over'
elif "red" in lowercase:
print "Nooooo!"
return 'death'
else:
return 'death'
# First Ninja scene, fight setup.
class Ninja(Scene):
def enter(self):
print ninja_intro
def action(self):
key_words = Scene.user_input(self)
for i in key_words:
if i in affirm:
strategy = raw_input("roundhouse to the face or jumping sidekick to the groin? ")
lower = strategy.lower()
key_words = lower.split(' ')
for i in key_words:
if i in ninja_kick1:
return 'smash'
elif i in ninja_kick2:
return 'brutal'
print "I'm afraid I don't know what a %s is " % strategy + title + "." + "Are you sure you want to fight?"
return Ninja.action(self)
elif i in negate:
print "Lucky for you, this ninja has a soft spot for pacifists.\n You win, simply in virtue of being a decent human being"
return 'over'
print nonsense + title + "."
return Ninja.action(self)
# First section of ninja fight
class Smash(Scene):
def enter(self):
print "Nice shot! He's stunned, how're you going to finish him: elbow or backfist?"
def action(self):
key_words = Scene.user_input(self)
for i in key_words:
if i == "elbow":
print "BOOM! He's down. There's no denying it, you're a badass!"
return 'over'
elif i == "backfist":
print "He ducks. Come on, you can do this. One more strike and he's down.\n Have you got one more left in you?"
finish_him = raw_input(prompt)
lower = finish_him.lower()
split = lower.split(' ')
for i in split:
if i in affirm:
luck = random.randint(0,2)
if luck <= 1:
print "You did it! He begs you for mercy. You walk away, head held high."
return 'over'
else:
print "Noooo! He's just too quick for you."
return 'death'
elif i in negate:
print "He floors you. Oh dear!"
return 'death'
print nonono + title + "."
return action.luck
print nonono + title + "."
return Smash.action
# Additional section of Ninja fight.
class Brutal(Scene):
def enter(self):
print "\nOuch! He goes flying, but comes back pissed off. Before you know it he's leaping through the air, his foot rapidly approaching your face. Do you jump left, right, or duck?"
def action(self):
key_words = Scene.user_input(self)
for i in key_words:
if i == "left":
left = random.randint(0,2)
if left == 0:
print ninja_miss_side
return 'over'
else:
print ninja_hit
return 'death'
elif i == "right":
right = random.randint(0,2)
if right == 0:
print ninja_miss_side
return 'over'
else:
print ninja_hit
return 'death'
elif i == "duck":
duck = random.randint(0,2)
if duck == 0:
print ninja_miss_duck
return 'over'
else:
print ninja_hit
return 'death'
print nonono + title + "."
return action
class EmptyRoom(Scene):
def enter(self):
if self.visit == 0:
print empty_room_intro
else:
print "OK, let's try this again." + empty_room_intro
self.visit =+ 1
def action(self):
choice = raw_input(prompt)
# try:
# return int(choice)
if "1" in choice:
print "Uh oh, back we go."
return 'wake_room'
elif "2" in choice:
print "Coolios"
return 'ocean'
elif "3" in choice:
print "Awesome."
return 'godot'
else:
print "1, 2 or 3. Was that really too much to ask for?"
return EmptyRoom.action(self)
# except valueError:
# print "Just a number, please."
# return EmptyRoom.action
class Ocean(Scene):
def enter(self):
print ocean_intro
def action(self):
key_words = Scene.user_input(self)
for i in key_words:
if i in affirm:
which_q = random.randint(0,3)
if which_q == 0:
return 'tortoise'
elif which_q == 1:
return 'overshoot'
else:
return 'greenpeace'
elif i in negate:
print defeatism
return 'death'
print nonono + title + "."
return Ocean.action(self)
class Tortoise(Scene):
def enter(self):
print tortoise_q
def action(self):
key_words = Scene.user_input(self)
for i in key_words:
if i == "2012":
print wrong_ocean_a
return 'death'
elif i == "2013":
print wrong_ocean_a
return 'death'
elif i == "2014":
print right_ocean_a
return 'over'
print nonono + title + "."
return Tortoise.action
class Overshoot(Scene):
def enter(self):
print overshoot_q
def action(self):
key_words = Scene.user_input(self)
for i in key_words:
if i == "August":
print right_ocean_a
return 'over'
elif i == "September":
print wrong_ocean_a
return 'death'
elif i == "October":
print wrong_ocean_a
return 'over'
print nonono + title + "."
return Overshoot.action
class Greenpeace(Scene):
def enter(self):
print greenpeace_q
def action(self):
key_words = Scene.user_input(self)
for i in key_words:
if i in greenpeace_a:
print right_ocean_a
return 'over'
else:
print wrong_ocean_a
return 'death'
class Historian(Scene):
def enter(self):
print historian_intro
def action(self):
key_words = Scene.user_input(self)
for i in key_words:
if i in affirm:
which_q = random.randint(0,3)
if which_q == 0:
return 'war'
elif which_q == 1:
return 'acidification'
else:
return 'poverty'
elif i in negate:
print defeatism
return 'death'
print nonono + title + "."
return Historian
class War(Scene):
def enter(self):
print war_q
def action(self):
key_words = Scene.user_input(self)
for i in key_words:
if i == "15th":
print wrong_history_a
return 'death'
elif i == "17th":
print wrong_history_a
return 'death'
elif i == "19th":
print "Congratulations, our historian is super impressed with your knowledge. She takes you on a tour of 2523, and even let's you take a souvenir home with you."
return 'over'
print nonono + title + "."
return War.action(self)
class Acidification(Scene):
def enter(self):
print acidification_q
def action(self):
key_words = Scene.user_input(self)
for i in key_words:
if i == "200":
print wrong_history_a
return 'death'
elif i == "300":
print "Correct. Scientists estimate that, as a consequence, sea oxygen levels will have dropped by as much as 7% by 2100."
return 'over'
elif i == "400":
print wrong_history_a
return 'death'
print nonono + title + "."
return Acidification.action
class Poverty(Scene):
def enter(self):
print poverty_q
def action(self):
key_words = Scene.user_input(self)
for i in key_words:
if i == "1.50":
print wrong_history_a
return 'death'
elif i == "1.90":
print "That's right. $1.90. A day. Did I mention, in 2012, 896 million people were still living below this line?"
return 'over'
elif i == "2.25":
print wrong_history_a
return 'death'
print nonono + title + "."
return Poverty.action
class Godot(Scene):
def enter(self):
print godot_intro
def action(self):
key_words = Scene.user_input(self)
for i in key_words:
if i in affirm:
print godot_outro
return 'over'
elif i in negate:
print "And so your life continues in much the same fashion as before this strange episode."
return 'over'
print "They all disappear in a puff of smoke."
return 'over'
class Over(Scene):
def enter(self):
print "Play again, or go do something productive with your day?"
key_words = Scene.user_input(self)
for i in key_words:
if i in play_again:
print wake_room_intro
a_map = Map("wake_room")
a_game = Engine(a_map)
a_game.play()
elif i in do_something:
print "Good for you! Go be in nature, fall in love, create something, experience some life. "
exit(1)
class Map(object): # Creates a map of the game with a dictionary of Scene instances.
scenes = {
'death': Death(),
'greeting': Greeting(),
'wake_room': WakeRoom(),
'wheel_room': WheelRoom(),
'pixie': Pixie(),
'empty_room': EmptyRoom(),
'wizard': Wizard(),
'riddle': Riddle(),
'child': Child(),
'space_time': SpaceTime(),
'historian': Historian(),
'war': War(),
'acidification': Acidification(),
'poverty': Poverty(),
'over': Over(),
'ocean': Ocean(),
'tortoise': Tortoise(),
'overshoot': Overshoot(),
'greenpeace': Greenpeace(),
'godot': Godot(),
'ninja': Ninja(),
'smash': Smash(),
'brutal': Brutal(),
}
def __init__(self, start_scene_key):
self.start_scene_key = start_scene_key
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_key)
a_map = Map('greeting') # sets a_map to an instance of class Map, with parameter 'greeting'.
a_game = Engine(a_map) # sets a_game to an instance of class Engine, with the parameter 'a_map'
a_game.play() # from Engine instance a_game, calls the play() method.