Skip to content

Commit f6e7017

Browse files
committed
change get_description function to override string method for class
1 parent d399b64 commit f6e7017

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

OOP/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@
5252
while dead == False:
5353

5454
print("\n")
55-
current_room.get_details()
56-
55+
print(current_room)
56+
5757
inhabitant = current_room.get_character()
5858
if inhabitant is not None:
5959
inhabitant.describe()

OOP/room.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,16 @@ def link_room(self, room_to_link, direction):
3838
self.linked_rooms[direction] = room_to_link
3939
#print( self.name + " linked rooms: " + repr(self.linked_rooms))
4040

41-
def get_details(self):
42-
print(self.name)
43-
print("--------------------")
44-
print(self.description)
41+
def __str__(self):
42+
desc = ''
43+
desc += self.name
44+
desc += "\n--------------------\n"
45+
desc += F"{self.description}\n"
4546
for direction in self.linked_rooms:
4647
room = self.linked_rooms[direction]
47-
print("The " + room.get_name() + " is " + direction)
48+
desc += F"The {room.get_name()} is direction {direction}.\n"
49+
50+
return desc
4851

4952
def move(self, direction):
5053
if direction in self.linked_rooms:

0 commit comments

Comments
 (0)