Skip to content

Commit 3b48e22

Browse files
committed
added room.py
1 parent 0c4f186 commit 3b48e22

1 file changed

Lines changed: 75 additions & 1 deletion

File tree

‎src/room.py‎

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,76 @@
11
# Implement a class to hold room information. This should have name and
2-
# description attributes.
2+
# description attributes.
3+
# Implement a class to hold room information. This should have name and
4+
# description attributes.
5+
6+
class Room (object):
7+
def __init__(self,name,description,items = [], is_light = None):
8+
"""
9+
Will initialize name description items is_light for the Room class.
10+
"""
11+
self.name = name
12+
self.description = description
13+
self.items = items
14+
self.n_to = None
15+
self.s_to = None
16+
self.e_to = None
17+
self.w_to = None
18+
self.directions = []
19+
self.is_light = is_light
20+
def __str__(self):
21+
"""
22+
will return the Room properties back as a string.
23+
"""
24+
return f"Room name: {self.name}\n\n, Room description: {self.description}\n\n Room has light : {self.is_light}"
25+
def revealItems(self):
26+
items = []
27+
for item in self.items:
28+
items.append((item.name, f"description {item.description}"))
29+
return (f"This room includes the following: {items}\n\n to pick up these items use keyword grab item_name\n\n")
30+
def getDirections(self):
31+
"""
32+
This function will return the directions and the rooms in those directions.
33+
"""
34+
return f"n: {self.n_to}, \n\n s: {self.s_to}, \n\n e: {self.e_to},\n\n w: {self.w_to}\n\n"
35+
def change_room(self, option):
36+
"""
37+
will return the room asscoaited with the choice between e w s n
38+
if the user makes in valid choice or even a false enter where nothing is entered in or
39+
a choice longer than required None is returned after a message printed letting the user
40+
know what they did wrong.
41+
"""
42+
option = option.lower()
43+
if len(option) != 1:
44+
print("Please choose from the following\n\n e\n w\n s\n n\n")
45+
return None
46+
if option == "n" and self.n_to is not None:
47+
print("n : You chose to go North")
48+
return self.s_to
49+
elif option == "s" and self.s_to is not None:
50+
print("s : You chose to go South")
51+
return self.s_to
52+
elif option == "w" and self.w_to is not None:
53+
print("w : You chose to go West")
54+
return self.w_to
55+
elif option == "e" and self.e_to is not None:
56+
print("e: You chose to go East")
57+
else:
58+
print("No room in that direction.")
59+
return None
60+
def removeItem(self, item):
61+
"""
62+
This function will take care of removing the itme if self.items has the item.
63+
returns a string of the item removed else returns None.
64+
"""
65+
if self.items.count(item) > 0:
66+
self.items.remove(item)
67+
return(f"{item.name} has been removed from the {self.name}\n\n to drop an item use drop item_name\n\n to check your inventory use i\n\n")
68+
else:
69+
return None
70+
def addItem(self, item):
71+
"""
72+
adding item to the room
73+
"""
74+
self.items.append(item)
75+
76+

0 commit comments

Comments
 (0)