-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.py
293 lines (265 loc) · 8.05 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
###############################
# Game.py #
##############################
# from storylines import stories
class Storyline:
def __init__(self, params, game):
self.text = params["text"],
self.prompt = params["prompt"]
self.options = params["options"]
self.step = params["step"]
self.game = game
self.conditions = params["conditions"]
def pass_game(self, game):
self.game = game
def print_game(self):
print(self.game.inventory)
def set_condition(self, new):
self.conditions = [new]
def __str__(self):
class_name = self.__class__.__name__
attributes = vars(self)
formatted_attributes = ',\n'.join(f"{attr} = {attributes[attr]}" for attr in attributes)
return f"{class_name} {{\n{formatted_attributes}\n}}"
class Game:
"""A class representing a generic room"""
def __init__(self, player, rooms):
self.stories = [
{
"text": """
Ghost: Eyes up, Guardian! You 0don't want to be late on your first day
with you0r new fireteam. What should I tell them to call you
""",
"prompt": "What is your name?",
"options": ["start"],
"conditions": [],
"step": 1,
},
{
"text": """
You have reached step 2
""",
"prompt": "what door would you like to take? 1",
"options": ["left", "right"],
"conditions": [],
"step": 2,
},
{
"text": """
You have reached step 3
""",
"prompt": "what do2or would you like to take? 2",
"options": ["left", "right"],
"conditions": [],
"step": 3,
},
{
"text": """
You have reached step 4
""",
"prompt": "what 3door would you like to take?3 ",
"options": ["left", "right"],
"conditions": [],
"step": 4,
},
{
"text": """
You have reached step 5
""",
"prompt": "4what door would you like to take?4",
"options": ["left", "right"],
"conditions": [],
"step": 5,
},
{
"text": """
You have reached step 6
""",
"prompt": "5what door would you like to take?5",
"options": ["left", "right"],
"conditions": [],
"step": 6,
}
]
self.state = {
"is_running": True,
"win_condition": False,
"current_room": 'Start',
"current_step": 0,
"move_on": False,
"current_storyline": None
}
self.story = [Storyline(params, self) for params in self.stories]
self.player_name = "Guardian"
self.current_prompt = 'Press any keys to start..............'
self.rooms = rooms
self.player = player
self.user_input = "start"
self.command_count = 0
self.step_cleared: False
self.commands = ['start']
self.valid_commands = [
"goto",
"take",
"back",
"showgame",
"colors",
"prog",
"move"
]
self.inventory = []
def check_step_win(self, condition):
if condition:
self.step_cleared = True
def set_state(self, new):
self.state[new[0]] = new[1]
def get_state(self):
return self.state
def do_side_effect(self, action):
return self.state
def start(self):
self.state["isRunning"] = True
def end(self, result):
self.state["win_condition"] = result
self.state["isRunning"] = False
def change_room(self, new_room):
self.set_state(["current_room", new_room])
def set_conditions(self, q, target):
questions = q
for i, room in enumerate(target):
room.conditions = questions[i]
def __str__(self):
class_name = self.__class__.__name__
attributes = vars(self)
formatted_attributes = ',\n'.join(f"{attr} = {attributes[attr]}" for attr in attributes)
return f"{class_name} {{\n{formatted_attributes}\n}}"
#
#
# class Storyline:
# def __init__(self, text, prompt, options, conditions, step: int):
# self.text = text,
# self.prompt = prompt
# self.options = options
# self.step = step
# self.conditions = []
# self.game = {}
#
# if not isinstance(self.text, tuple):
# raise TypeError("Storyline.text must be of type int")
#
# if not isinstance(self.prompt, str):
# raise TypeError("Storyline.prompt must be of type int")
#
# if not isinstance(self.options, list):
# raise TypeError("Storyline.options must be of type list")
#
# if not isinstance(self.step, int):
# raise TypeError("Storyline.step must be of type int")
#
# if not isinstance(self.conditions, list):
# raise TypeError("Storyline.conditions must be of type int")
#
# def pass_game(self, game):
# self.game = game
#
# def __str__(self):
# class_name = self.__class__.__name__
# attributes = vars(self)
# formatted_attributes = ',\n'.join(f"{attr} = {attributes[attr]}" for attr in attributes)
# return f"{class_name} {{\n{formatted_attributes}\n}}"
#
#
#
# story = [
# {
# text:"""Ghost: Eyes up, Guardian! You 0don't want to be late on your first day with you0r new fireteam. What should I tell them to call you""",
# prompt: "What is your name?",
# options: ["start"],
# conditions: [("penis" in game.inventory)],
# step: 0,
# },
#
# Storyline(
# text="""
# You have reached step 2
# """,
# prompt="what door would you like to take? 1",
# options=["left", "right"],
# conditions=[],
# step=1,
# ),
# Storyline(
# text="""
# You have reached step 3
# """,
# prompt="what do2or would you like to take? 2",
# options=["left", "right"],
# conditions=[],
# step=2,
# ),
# Storyline(
# text="""
# You have reached step 4
# """,
# prompt="what 3door would you like to take?3 ",
# options=["left", "right"],
# conditions=[],
# step=3,
# ),
# Storyline(
# text="""
# You have reached step 5
# """,
# prompt="4what door would you like to take?4",
# options=["left", "right"],
# conditions=[],
# step=4,
# ),
# Storyline(
# text="""
# You have reached step 6
# """,
# prompt="5what door would you like to take?5",
# options=["left", "right"],
# conditions=[],
# step=5,
# ),
# Storyline(
# text="""
# You have reached step 7
# """,
# prompt="6what door would you like to take?",
# options=["left", "right"],
# conditions=[],
# step=6,
# ),
# Storyline(
# text="""
# You have reached step 8
# """,
# prompt="7what do7or would you like to take?",
# options=["left", "right"],
# conditions=[],
# step=7,
# ),
# Storyline(
# text="""
# You have reached step 9
# """,
# prompt="8what door would you like to take?",
# options=["left", "right"],
# conditions=[],
# step=8,
# ),
# Storyline(
# text="""
# You have reached step 10
# """,
# prompt="what door 9would you like to take?",
# options=["left", "right"],
# conditions=[],
# step=9,
# ),
#
# ]
#