Advertisement
TonyMo

room.py

Mar 14th, 2021
843
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.01 KB | None | 0 0
  1. # 2 3 room.py  26 27 29 210 36 now 38
  2. # ref  3 6 Aggregation .htm
  3.  
  4. class Room():
  5.     def __init__(self, room_name):
  6.         self.name = room_name
  7.         self.description = None
  8.         self.linked_rooms = {}  #2 6 dictionary
  9.         self.character = None   #3 6 a room now has the ability to contain a character.
  10.  
  11.     def set_description(self, room_description):        # 2 5 Setters & Getters
  12.         self.description = room_description
  13.  
  14.     def get_description(self):  # used to pass the result on
  15.         return self.description
  16.  
  17.     def set_name(self, room_name):
  18.         self.name = room_name
  19.  
  20.     def get_name(self):
  21.         return self.name
  22.  
  23.     def set_character(self, new_character): #3 6 to enable putting a character inside a room
  24.         self.character = new_character
  25.  
  26.     def get_character(self):    #3 6 to enable putting a character inside a room
  27.         return self.character
  28.  
  29.     def describe(self):
  30.         print( self.description )
  31.         # print( self.name + ". " + self.description )
  32.  
  33.     def link_room(self, room_to_link, direction): # 2 6 add link method
  34.         self.linked_rooms[direction] = room_to_link
  35.         # print( self.name + " linked rooms :" + repr(self.linked_rooms) )
  36.  
  37.     '''2.7 add a new method that will display
  38.       all the rooms linked to the current room object.'''
  39.  
  40.     def get_details(self):
  41.         print("You are in the " + self.name + ".\n~~~~~~~~~~~~")
  42.         print(self.description)
  43.         # print(self. item_description)
  44.         for direction in self.linked_rooms:
  45.             room = self.linked_rooms[direction]
  46.             print(" The " + room.get_name() + " is " + direction +".")
  47.         print() #outputs a blank line after each room information.
  48.  
  49.         # 2.9 moving between rooms
  50.     def move(self, direction):
  51.         if direction in self.linked_rooms:
  52.             return self.linked_rooms[direction]
  53.         else:
  54.             print("You can't go that way")
  55.         return self     # OK indentations corrected
  56.  
  57.         # 2.10 see item.py
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement