Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 2 3 room.py 26 27 29 210 36 now 38
- # ref 3 6 Aggregation .htm
- class Room():
- def __init__(self, room_name):
- self.name = room_name
- self.description = None
- self.linked_rooms = {} #2 6 dictionary
- self.character = None #3 6 a room now has the ability to contain a character.
- def set_description(self, room_description): # 2 5 Setters & Getters
- self.description = room_description
- def get_description(self): # used to pass the result on
- return self.description
- def set_name(self, room_name):
- self.name = room_name
- def get_name(self):
- return self.name
- def set_character(self, new_character): #3 6 to enable putting a character inside a room
- self.character = new_character
- def get_character(self): #3 6 to enable putting a character inside a room
- return self.character
- def describe(self):
- print( self.description )
- # print( self.name + ". " + self.description )
- def link_room(self, room_to_link, direction): # 2 6 add link method
- self.linked_rooms[direction] = room_to_link
- # print( self.name + " linked rooms :" + repr(self.linked_rooms) )
- '''2.7 add a new method that will display
- all the rooms linked to the current room object.'''
- def get_details(self):
- print("You are in the " + self.name + ".\n~~~~~~~~~~~~")
- print(self.description)
- # print(self. item_description)
- for direction in self.linked_rooms:
- room = self.linked_rooms[direction]
- print(" The " + room.get_name() + " is " + direction +".")
- print() #outputs a blank line after each room information.
- # 2.9 moving between rooms
- def move(self, direction):
- if direction in self.linked_rooms:
- return self.linked_rooms[direction]
- else:
- print("You can't go that way")
- return self # OK indentations corrected
- # 2.10 see item.py
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement