Question: In simple Python: Create a class called Room, for storing information about the locations that the player and monster will be moving through. Rooms have
In simple Python: Create a class called Room, for storing information about the locations that the player and monster will be moving through. Rooms have two public attributes for storing the name of the room (e.g., "the docking bay" or "a long hallway") and the room number. The constructor should set both a name and a room number Room objects should also have a non-public attribute storing the list* of other Rooms that this Room is connected to. When the constructor creates a new Room, the list of exits should start out as empty.
To add connections between rooms, create a method called .connect_to(), which takes another Room or an iterable of Rooms and adds connections between them. Note that in addition to adding the other Room to the current Room's exit list, you will also need to add the current Room to the other Room's exit list. Since the exit list is not public, you should also create a getter for it.
Write a method called .is_connected_to() which determines whether or not two Rooms are connected. So a command like lab.is_connected_to(hall) would return True if there's a connection between lab and hall, and it would return False if there is no such connection. Write a method called .description() which returns a string representing a description of the Room. The description should include the name of the Room and a list of the room numbers of adjacent rooms.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
