-
Notifications
You must be signed in to change notification settings - Fork 0
/
.~c9_invoke_VyCvHe.py
226 lines (179 loc) · 8.25 KB
/
.~c9_invoke_VyCvHe.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
# from classes import Item, Weapon, Food, Room, Player, Creature
# from world import initRooms
# import move
import pickle
import os
from boto
s3 = S3Connection('AKIAIWDQLBLAQWDY4DCQ', 'pFQgHEyd5bi0QkZjGXbjnmMA1N5ZE8ioKq3iM0y9')
s3 = boto.s3.connect_to_region(
self.settings.region,
aws_access_key_id=unwrap(self.settings.aws_access_key_id),
aws_secret_access_key=unwrap(self.settings.aws_secret_access_key)
)
bucket = s3.get_bucket('ichackgame', validate=False)
key = bucket.new_key('save.dat')
#------------REGION 1: THE JUNGLE------------
class Room:
def __init__(self, name, location, description, items, creatures, indoors, locks):
self.name = name # String
self.location = location # (x,y,z)
self.description = description # String
self.items = items # [Item Obj]
self.indoors = indoors # Boolean
self.locks = locks #array of booleans
def getItems(self):
return self.items
def takeItem(self, item):
return self.items.remove(item)
def dropItem(self, item):
return self.items.append(item)
def getXCoord(self):
return self.location[0]
def getYCoord(self):
return self.location[1]
def getZCoord(self):
return self.location[2]
def isIndoors(self):
return self.indoors
def hasItem(self, itemName): # returns boolean
for item in items:
if item.getName == itemName:
return True
return False
class Player:
def __init__(self, name, inventory, health, room):
self.name = name # String
self.inventory = inventory # [Items Obj]
self.health = health # Int
self.room = room # Room Obj
def getRoom(self):
return self.room
warehouse = Room("Warehouse", [0,0,0], """You are in what appears to be a large abandoned amazon fulfilment centre.
Rows of shelves stretch along the warehouse. The floor is littered with long-dead package retrieval robots.
There is no sound, and almost no light, save for a faint glow from a large green message scrawled
on the north wall. The message reads: if you seek answers, journey north and find headquarters.
Under the text, you can see a door, slightly ajar. There do not appear to be any other exits""",[],[], True,[])
jungle_SW = Room("Southwest Jungle",[1,0,0],"",[], [], False, [])
initRooms = [
warehouse,
jungle_SW,
]
# ---
def save():
# Insert soundEffect_gunshotPistol or another sfx into toSay string when needed"
soundEffect_gunshotPistol = '<audio src="https://s3.eu-west-2.amazonaws.com/ichackgame/pistol.mp3"/>'
# -- Save functions --
def save():
key.set_contents_from_string(pickle.dumps([player, rooms]))
def load():
p , rs = pickle.load(key.get_contents_as_string())
global player
player = p
global rooms
rooms = rs
# -- Game functions
def getInventory():
if player is not None:
return [item.getName() for item in player.getInv()]
else:
return None
def getRoomWithCoords(x,y,z):
for room in rooms:
if (room.getXCoord == x and room.getYCoord == y and room.getZCoord == Z):
return room
return None
def play(slots, new=False):
toSay = ""
isDead = False
if (new):
global player
player = Player("Jeff",[],100,Room("Warehouse", [0,0,0], "You are in what appears to be a large abandoned amazon fulfilment centre. Rows of shelves stretch along the warehouse. The floor is littered with long-dead package retrieval robots.There is no sound, and almost no light, save for a faint glow from a large green message scrawledon the north wall. The message reads: if you seek answers, journey north and find headquarters. Under the text, you can see a door, slightly ajar. There do not appear to be any other exits",[],[], True,[]))
global rooms
rooms = initRooms
save()
toSay = "You're a dumb dumb"
return toSay
else:
load()
currentRoom = warehouse# player.getRoom()
roomItems = currentRoom.getItems()
if all ("value" in slots[key] for key in ("AVerb","BNoun","CUsing","DNoun")):
values = {}
toSay = ""
# -- temp
for key in ("AVerb","BNoun","CUsing","DNoun"):
values[key] = slots[key]['value']
toSay = "You %(AVerb)s %(BNoun)s with %(DNoun)s" % values
return {"toSay":toSay, "isDead":isDead}
# temp
for key in ("AVerb","BNoun","CUsing","DNoun"):
values[key] = slots[key]['value']
if (len(player.getInv) == 0) or (player.hasItem(DNoun)):
toSay = "You don't have a %(BNoun)s" % values
elif (not currentRoom.hasItem(values['DNoun'])): # check if thing in room
toSay = "%(BNoun)s is not in here to %(AVerb)s" % values
else:
toSay = "You %(AVerb)s %(BNoun)s with %(DNoun)s" % values
# GAME LOGIC
# res = currentRoom.quarternaryCommand()
# You went up into tree
elif all ("value" in slots[key] for key in ("AVerb","BNoun","CLoc","DNoun")):
values = {}
for key in ("AVerb","BNoun","CLoc","DNoun"):
values[key] = slots[key]['value']
if (not currentRoom.hasItem(values['DNoun'])): # check if thing in room
toSay = "%(BNoun)s is not here!" % values
else:
# temp
flag = False
# Check if possible
#else
toSay = "You can't %(AVerb)s %(BNoun)s %(CLoc)s %(DNoun)s" % values
toSay += ""
# GAME LOGIC
# res = currentRoom.quarternaryCommand()
elif all ("value" in slots[key] for key in ("AVerb","BSwitch","CNoun")):
values = {}
for key in ("AVerb","BSwitch","CNoun"):
values[key] = slots[key]['value']
if (values['CNoun'] not in roomItems): # check if thing in room
toSay = "%(CNoun)s is not in here to %(AVerb)s" % values
# TODO
# elif (roomItems): # is not switcahble
# toSay = ""
else:
# res = currentRoom.something() Check if valid
toSay = "You %(AVerb)s %(BSwitch)s %(CNoun)." % values
toSay += ""
# Go into trapdoor
elif all ("value" in slots[key] for key in ("AVerb","BLoc","CNoun")):
values = {}
for key in ("AVerb","BSwitch","CNoun"):
values[key] = slots[key]['value']
if (values['CNoun'] not in roomItems): # check if thing in room
toSay = "No %(CNoun)s here" % values
# TODO
# elif (roomItems): # cannot have movement action
# toSay = ""
else:
# res = currentRoom.something() Check if valid
toSay = "You %(AVerb)s %(BSwitch)s %(CNoun)." % values
toSay += ""
elif all ("value" in slots[key] for key in ("AVerb","BNoun")):
values = {}
for key in ("AVerb","BNoun"):
values[key] = slots[key]['value']
if (values['BNoun'] not in roomItems): # check if thing in room
toSay = "No %(CNoun)s here" % values
else:
toSay = "You %(AVerb)s %(BNoun)s." % values
# tries moving
# m = move.initMove(values['AVerb'],values['BNoun'],rooms,player)
# if (m != False):
# (x,y,z) = m
# player.setRoom(getRoomWithCoords(x,y,z))
# else:
# toSay += ""
else:
toSay = "I don't understand!"
return {"toSay":toSay, "isDead":isDead}