forked from Team-Big-Bosses/CS-Build-Week-1-Flask
/
room.py
68 lines (61 loc) · 1.9 KB
/
room.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
# Implement a class to hold room information. This should have name and
# description attributes.
from store import Store
class Room:
def __init__(self, name, description, id=0, x=None, y=None, items=[], store=None):
self.id = id
self.name = name
self.description = description
self.n_to = None
self.s_to = None
self.e_to = None
self.w_to = None
self.x = x
self.y = y
self.items = items
self.store = store
def get_exits(self):
exits = []
if self.n_to is not None:
exits.append("n")
if self.s_to is not None:
exits.append("s")
if self.w_to is not None:
exits.append("w")
if self.e_to is not None:
exits.append("e")
return exits
def get_items(self):
item_names = []
for item in self.items:
item_names.append(item.name)
return item_names
def connect_rooms(self, direction, connecting_room):
if direction == "n":
self.n_to = connecting_room
connecting_room.s_to = self
elif direction == "s":
self.s_to = connecting_room
connecting_room.n_to = self
elif direction == "e":
self.e_to = connecting_room
connecting_room.w_to = self
elif direction == "w":
self.w_to = connecting_room
connecting_room.e_to = self
else:
print("INVALID ROOM CONNECTION")
return None
def get_room_in_direction(self, direction):
if direction == "n":
return self.n_to
elif direction == "s":
return self.s_to
elif direction == "e":
return self.e_to
elif direction == "w":
return self.w_to
else:
return None
def get_coords(self):
return [self.x, self.y]