forked from bloominstituteoftechnology/CS-Build-Week-2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroom.py
57 lines (57 loc) · 1.81 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
class Room:
def __init__(self, name, description, id=0, x=None, y=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
def __str__(self):
return f"\n-------------------\n\n{self.name}\n\n {self.description}\n\n{self.getExitsString()}\n"
def printRoomDescription(self, player):
print(str(self))
def getExits(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 getExitsString(self):
return f"Exits: [{', '.join(self.getExits())}]"
def connectRooms(self, direction, connectingRoom):
if direction == "n":
self.n_to = connectingRoom
connectingRoom.s_to = self
elif direction == "s":
self.s_to = connectingRoom
connectingRoom.n_to = self
elif direction == "e":
self.e_to = connectingRoom
connectingRoom.w_to = self
elif direction == "w":
self.w_to = connectingRoom
connectingRoom.e_to = self
else:
print("INVALID ROOM CONNECTION")
return None
def getRoomInDirection(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 getCoords(self):
return [self.x, self.y]