class Room(object): def __init__(self, name, description, exits, contents): """ NB. A list must be passed into exits """ self.self = self self.name = name self.description = description self.exits = exits self.inventory = Inventory() for item in contents: self.inventory.add_item(item) def on_entering_room(self): print "You have entered the %s" % self.name def objects_in_room(self): print self.inventory.list_of_items()
class Item(object): """Base item class""" def __init__(self, id, name, description, contents=None): self.id = id self.name = name self.description = description if contents == None: self.inventory = False else: self.inventory = Inventory() for item in contents: self.inventory.add_item(item) # Base methods # These can be overridden in more complex items. def look(self): print self.description def look_in(self): print "%s contain: " % self.name, self.inventory.list_of_items()