Write a program using an object
Start to create your object-oriented text-based adventure game
Extend other people’s classes
Create an enemy in the room
Recap Week 3
Extending your knowledge of OOP
Finish your game
End of the course
When entering a room in the game, the game displays a description of that room to the player, for example:
The dining hall
-------------------
A large room with ornate golden decorations on every wall
The kitchen is north
The ballroom is west
Next, you will add a new method to the Room class to report the room name and description and the directions of all the rooms connected to it.
Go back to the Room class and add a new method that will display all the rooms linked to the current room object. Don’t forget to make sure the new method is indented, just like all the other methods.
def get_details(self):
for direction in self.linked_rooms:
room = self.linked_rooms[direction]
print( "The " + room.get_name() + " is " + direction)
This method loops through the dictionary self.linked_rooms and, for every defined direction, prints out that direction and the name of the room in that direction.
Go back to the main.py file and, at the bottom of your script, call this method on the dining hall object, then run the code to see the two rooms linked to the dining hall.
dining_hall.get_details()
Add the code to the get_details() method so that it also prints out the name and description of the current room, as in the example above. Remember that you can refer to the current room as self inside the method.
Check that your get_details() method works for any room object by calling it on the kitchen and ballroom as well.