-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththe_whisperer_in_darkness.py
387 lines (291 loc) · 15.2 KB
/
the_whisperer_in_darkness.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
from translator import Translator
# from slot_types import Door
# from slot_types import LeftRight
from audio import Audio
from alexa_helper import StateVariables
from alexa_helper import StateHelper
from slot_types import Room
from response import Response
class TheWhispererInDarkness :
ROOM = "Room"
HAS_KEY = "HasKey"
CHAINS_INVESTIGATED = "ChainsInvestigated"
BOOK_UNLOCKED = "BookLocked"
HAS_BOOK = "HasBook"
CHEST_OPENED = "ChestOpened"
MIRROR_BROKEN = "MirrorBroken"
@staticmethod
def handle_launch() :
return Response(Translator.Launch, should_save_speech_text=False)
@staticmethod
def generic_error_response():
return Response(Translator.GenericError, should_save_speech_text=False)
@staticmethod
def enter_door(door, state_variables):
"""
TODO
"""
speech_text = None
# if door is a Door then use it to choose which door, else assume door is a string
if (door is None):
speech_text = Translator.DoorError
elif ((isinstance(door, str) and door.upper() in ["FIRST", "LEFT", "ONE", "1"]) or door == 1):
state_variables[TheWhispererInDarkness.ROOM] = Room.octopus
speech_text = Translator.LeftDoor
elif ((isinstance(door, str) and door.upper() in ["SECOND", "RIGHT", "TWO", "2"]) or door == 2):
state_variables[TheWhispererInDarkness.ROOM] = Room.mirror
speech_text = Translator.RightDoor
else:
speech_text = Translator.DoorError
return Response(speech_text, state_variables = state_variables)
@staticmethod
def investigate_chains(state_variables) :
speech_text = None
if(Room(state_variables[TheWhispererInDarkness.ROOM]) == Room.mirror) :
if(state_variables[TheWhispererInDarkness.CHAINS_INVESTIGATED] == False) :
speech_text = Translator.InvestigateChains
state_variables[TheWhispererInDarkness.CHAINS_INVESTIGATED] = True
else :
speech_text = Translator.AlreadyInvestigatedChains
# Error catching
if(speech_text == None) :
speech_text = Translator.ChainsError
return Response(speech_text, state_variables = state_variables)
@staticmethod
def use_key(state_variables):
speech_text = None
#In the mirror room
if(Room(state_variables[TheWhispererInDarkness.ROOM]) == Room.mirror) :
# And you have the key
if(state_variables[TheWhispererInDarkness.HAS_KEY] == True) :
# And you dont already have the book
if(state_variables[TheWhispererInDarkness.HAS_BOOK] == False) :
state_variables[TheWhispererInDarkness.BOOK_UNLOCKED] = True
speech_text = Translator.UseKey
# But you already have the book
elif(state_variables[TheWhispererInDarkness.HAS_BOOK] == True) :
speech_text = Translator.GenericError
#But you dont have the key
elif(state_variables[TheWhispererInDarkness.HAS_KEY] == False) :
speech_text = Translator.GenericError
#If you in any room but the mirror room
elif(state_variables[TheWhispererInDarkness.HAS_KEY] == False) :
speech_text = Translator.GenericError
if(speech_text == None) :
speech_text = Translator.GenericError
return Response(speech_text, state_variables = state_variables)
@staticmethod
def open_book(state_variables):
speech_text = None
#In the mirror room
if(Room(state_variables[TheWhispererInDarkness.ROOM]) == Room.mirror) :
#If book is no longer in chains
if(state_variables[TheWhispererInDarkness.BOOK_UNLOCKED] == True) :
#If you dont have the book yet / havent tried to open it yet
if(state_variables[TheWhispererInDarkness.HAS_BOOK] == False) :
speech_text = Translator.OpenBookInMirrorRoom
state_variables[TheWhispererInDarkness.HAS_BOOK] = True
#If you have already opened the book in the mirror room
elif(state_variables[TheWhispererInDarkness.HAS_BOOK] == True) :
speech_text = Translator.OpenBook_NotNeeded
#If book is still in chains
elif(state_variables[TheWhispererInDarkness.BOOK_UNLOCKED] == False) :
speech_text = Translator.OpenBook_ItsLocked
#In the lobby room
elif(Room(state_variables[TheWhispererInDarkness.ROOM]) == Room.lobby) :
#If you have the book
if(state_variables[TheWhispererInDarkness.HAS_BOOK] == True ) :
#If the mirror has yet to be be broken
if(state_variables[TheWhispererInDarkness.MIRROR_BROKEN] == False) :
# If the octopus has been released when you break the glass, trigger game exit
if(state_variables[OctopusRoom.IS_OCTOPUS_RELEASED] == True) :
speech_text = Translator.OpenBookInLobby + Translator.EndGame
elif(state_variables[OctopusRoom.IS_OCTOPUS_RELEASED] == False) :
speech_text = Translator.OpenBookInLobby
state_variables[TheWhispererInDarkness.MIRROR_BROKEN] = True
#If the mirror is already broken
elif(state_variables[TheWhispererInDarkness.MIRROR_BROKEN] == True):
speech_text = Translator.OpenBook_NotNeeded
#If you DON'T have the book
elif(state_variables[TheWhispererInDarkness.HAS_BOOK] == False):
speech_text = Translator.GenericError
#In the octopus room
elif(Room(state_variables[TheWhispererInDarkness.ROOM]) == Room.octopus) :
speech_text = Translator.GenericError
#Final error catch
if(speech_text == None) :
speech_text = Translator.DebugError
return Response(speech_text, state_variables = state_variables)
@staticmethod
def leave_room(state_variables):
speech_text = None
#If the player is in any room EXCEPT for the lobby
if(Room(state_variables[TheWhispererInDarkness.ROOM]) != Room.lobby):
state_variables[TheWhispererInDarkness.ROOM] = Room.lobby
speech_text = Translator.LeaveMirrorRoom
#If the player is in the lobby
elif(Room(state_variables[TheWhispererInDarkness.ROOM]) == Room.lobby):
speech_text = Translator.LeaveRoomError
#Final error catch
if(speech_text == None) :
speech_text = Translator.DebugError
return Response(speech_text, state_variables = state_variables)
@staticmethod
def throw_book(state_variables) :
speech_text = None
#if the player has the book
if(state_variables[TheWhispererInDarkness.HAS_BOOK] == True) :
speech_text = Translator.ThrowBook
#else if the player doe not have the book
elif(state_variables[TheWhispererInDarkness.HAS_BOOK] == False) :
speech_text = Translator.GenericError
#Final error catch
if(speech_text == None) :
speech_text = Translator.DebugError
return Response(speech_text, state_variables = state_variables)
@staticmethod
def open_chest(state_variables) :
state_helper = StateHelper(lambda: state_variables)
room = Room(state_helper.get_state(TheWhispererInDarkness.ROOM))
speech_text = None
#In the mirror room
if(room == Room.mirror) :
#If the player does not already have the key
if(state_variables[TheWhispererInDarkness.CHEST_OPENED] == False) :
state_variables[TheWhispererInDarkness.CHEST_OPENED] = True
speech_text = Translator.OpenChest
#if the player already has the key
elif(state_variables[TheWhispererInDarkness.CHEST_OPENED] == True) :
speech_text = Translator.GenericError
# If the player is in any room BUT the mirror room
elif(room != Room.mirror) :
speech_text = Translator.GenericError
#Final error catch
if(speech_text == None) :
speech_text = Translator.DebugError
return Response(speech_text, state_variables = state_variables)
@staticmethod
def reach_in_chest(state_variables) :
speech_text = None
#In the mirror room
if(Room(state_variables[TheWhispererInDarkness.ROOM]) == Room.mirror) :
# And the chest is opened / been investigated
if(state_variables[TheWhispererInDarkness.CHEST_OPENED] == True) :
state_variables[TheWhispererInDarkness.HAS_KEY] = True
speech_text = Translator.ReachInChest
# The chest hasn not been opened yet
elif(state_variables[TheWhispererInDarkness.CHEST_OPENED] == False) :
speech_text = Translator.GenericError
# If the player is in any room BUT the mirror room
elif(Room(state_variables[TheWhispererInDarkness.ROOM]) != Room.mirror) :
speech_text = Translator.GenericError
#Final error catch
if(speech_text == None) :
speech_text = Translator.DebugError
return Response(speech_text, state_variables)
@staticmethod
def help() :
speech_text = Translator.Help
return Response(speech_text)
@staticmethod
def fallback() :
speech_text = Translator.GenericError
return Response(speech_text)
@staticmethod
def repeat_riddle() :
speech_text = Translator.RepeatRiddle
return Response(speech_text)
class OctopusRoom :
IS_OCTOPUS_RELEASED = "IsOctopusReleased"
IS_AQUARIUM_OPEN = "IsAquariumOpen"
@staticmethod
def wardrobe(state_variables):
should_save_speech_text = True
# we use state helper since it automatically converts key errors into None
state_helper = StateHelper(lambda: state_variables)
is_aquarium_open = state_helper.get_state(OctopusRoom.IS_AQUARIUM_OPEN)
is_octopus_released = state_helper.get_state(OctopusRoom.IS_OCTOPUS_RELEASED)
is_mirror_broken = state_helper.get_state(TheWhispererInDarkness.MIRROR_BROKEN)
room = state_helper.get_state(TheWhispererInDarkness.ROOM)
in_octopus_room = room is not None and Room(room) == Room.octopus
if (not in_octopus_room):
should_save_speech_text=False
speech_text = Translator.GenericError
elif (not is_aquarium_open and not is_octopus_released):
speech_text = Translator.Octopus_OpenWardrobeBeforeAquarium
elif (is_aquarium_open and not is_octopus_released):
speech_text = Translator.Octopus_OpenWardrobeBeforeOctopusRelease
elif (is_aquarium_open and is_octopus_released):
state_variables[TheWhispererInDarkness.ROOM] = Room.lobby
if (is_mirror_broken):
speech_text = Translator.Octopus_OpenWardrobeToExitBeach + Translator.EndGame
else:
speech_text = Translator.Octopus_OpenWardrobeToExitBeach
else:
speech_text = Translator.DebugError
response = Response(speech_text, state_variables=state_variables, should_save_speech_text=should_save_speech_text)
return response
@staticmethod
def octopus(state_variables):
should_save_speech_text = True
# we use state helper since it automatically converts key errors into None
state_helper = StateHelper(lambda: state_variables)
is_octopus_released = state_helper.get_state(OctopusRoom.IS_OCTOPUS_RELEASED)
room = state_helper.get_state(TheWhispererInDarkness.ROOM)
in_octopus_room = room is not None and Room(room) == Room.octopus
if (not in_octopus_room):
should_save_speech_text=False
speech_text = Translator.GenericError
if (is_octopus_released):
should_save_speech_text=False
speech_text = Translator.Octopus_OctopusAlreadyReleased + "\n" + Translator.Octopus_ExprienceTheBeach
else:
speech_text = Translator.Octopus_ReleaseOctopusBecomeBeach
state_variables[OctopusRoom.IS_OCTOPUS_RELEASED]
response = Response(speech_text, state_variables=state_variables, should_save_speech_text=should_save_speech_text)
return response
@staticmethod
def bad_octopus(state_variables):
should_save_speech_text = True
# we use state helper since it automatically converts key errors into None
state_helper = StateHelper(lambda: state_variables)
is_octopus_released = state_helper.get_state(OctopusRoom.IS_OCTOPUS_RELEASED)
room = state_helper.get_state(TheWhispererInDarkness.ROOM)
in_octopus_room = room is not None and Room(room) == Room.octopus
if (not in_octopus_room):
should_save_speech_text=False
speech_text = Translator.GenericError
if (is_octopus_released):
should_save_speech_text=False
speech_text = Translator.Octopus_OctopusAlreadyReleased + "\n" + Translator.Octopus_ExprienceTheBeach
else:
#TODO can we add octopus specific audio here?
speech_text = Translator.WrongThingToDo
state_variables[OctopusRoom.IS_OCTOPUS_RELEASED]
response = Response(speech_text, state_variables=state_variables, should_save_speech_text=should_save_speech_text)
return response
@staticmethod
def aquarium(state_variables):
should_save_speech_text = True
# we use state helper since it automatically converts key errors into None
state_helper = StateHelper(lambda: state_variables)
is_aquarium_open = state_helper.get_state(OctopusRoom.IS_AQUARIUM_OPEN)
is_octopus_released = state_helper.get_state(OctopusRoom.IS_OCTOPUS_RELEASED)
room = state_helper.get_state(TheWhispererInDarkness.ROOM)
in_octopus_room = room is not None and Room(room) == Room.octopus
if (not in_octopus_room):
should_save_speech_text=False
speech_text = Translator.GenericError
elif (is_aquarium_open and is_octopus_released):
should_save_speech_text = False
speech_text = Translator.Octopus_AquariumShatters + "\n" + Translator.Octopus_ExprienceTheBeach
elif (is_aquarium_open and not is_octopus_released):
state_variables[OctopusRoom.IS_OCTOPUS_RELEASED] = False
speech_text = Translator.Octopus_ReleaseOctopusBecomeBeach
elif (not is_aquarium_open and not is_octopus_released):
state_variables[OctopusRoom.IS_AQUARIUM_OPEN] = True
speech_text = Translator.Octopus_OpenAquarium
else:
speech_text = Translator.DebugError
response = Response(speech_text, state_variables=state_variables, should_save_speech_text=should_save_speech_text)
return response