-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.py
129 lines (99 loc) · 3.16 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
from sys import exit
from random import randint
class Scene(object):
def enter(self):
print "This scene is not yet configured. Subclass it and implement enter()."
exit(1)
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 Finished(Scene):
def enter(self):
print "You won! Good job."
return 'finished'
class Fail(Scene):
def enter(self):
print "Sorry you failed, please try again."
exit(1)
class Start(Scene):
def enter(self):
print 'You are in an infinite loophole, you need to get out of there!'
print 'There are two doors:'
print '#1 Leads to heaven'
print '#2 Leads to hell'
print "But you don't know which door leads to what"
print 'Which one will you choose?'
b = raw_input('>' )
n = randint(1,2)
if b == str(n):
return 'heaven'
else:
return 'hell'
class Heaven(Scene):
def enter(self):
print 'Congratulations, you have reached heaven!'
print 'Do you regret your decision?'
b = raw_input('>' )
if b == 'yes' or b == 'y':
return 'start'
elif b == 'no' or b == 'n':
print 'There are three doors in front of you:'
print 'Entering door #1 makes you very wise.'
print 'Entering door #2 gives you infinte money.'
print 'Entering door #3 leads you to god.'
print 'Which one do you choose?'
a = raw_input("[keypad]>" )
if a == '1':
print 'You are selfless!!'
return 'finished'
elif a == '2':
print 'You greedy bastard!, you stay in loophole for years and never come out.'
return 'fail'
elif a == '3':
print 'You reach heaven and you die!'
return 'fail'
else:
return 'heaven'
else:
print 'Please write correctly'
return 'heaven'
class Hell(Scene):
def enter(self):
print 'BEWARE! YOU HAVE REACHED HELL'
print 'You can still go back, going to hell is going to be a very difficult task'
print 'Do you want to go back?'
b = raw_input('>' )
if b == 'yes' or b =='y':
print 'You are such a coward, you stay in loophole for years and never come out.'
return 'fail'
elif b == 'no' or b == 'n':
print 'You are a brave man, you sucessfully come out of loophole'
#print 'Congratulations, you win!'
return 'finished'
else:
print 'Please write correctly'
return 'hell'
class Map(object):
scenes = { 'start': Start(),
'hell': Hell(),
'heaven': Heaven(),
'fail': Fail(),
'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)
a_map = Map('start')
a_game = Engine(a_map)
a_game.play()