Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #def room(status): #This is the template for each room
- #room = """description""" #This description is read now and can be printed at will later
- #print room
- #valid = False
- #while not valid: #This is the command loop, player can keep entering commands at will
- #choice = raw_input ('> ')
- #choice = choice.lower()
- #if "statdebug" in choice: #A debug routine that let's me see what is in Status while testing
- #print status
- #elif "look" in choice: #Allows player ro redisplay the description
- #print room
- #elif input: #Room specific commands
- #bla bla bla
- #else: #General error trap for unrecognised commands
- #print "Command not recognized"
- #return status
- #room description
- #room exists
- #room inventory
- class Room(object):
- def __init__(self, name, description):
- self.setName(name)
- self.setDescription(description)
- # Here
- self.exits = {"NORTH": None,
- "EAST": None,
- "SOUTH": None,
- "WEST": None}
- self.inventory = []
- def __repr__(self):
- # Return a string that will show up when you print the room
- rstring = self.getName() + "\n"
- rstring += self.getDescription()
- return rstring
- #print MainHall
- # Name methods
- def setName(self, name):
- self.name = name + " in cool guy manor"
- def getName(self):
- return self.name
- # Description methods
- def setDescription(self, descr):
- self.description = descr
- def getDescription(self):
- return self.description
- # exit methods
- def addExit(self, direction, exitRoom):
- self.exits[direction] = exitRoom
- def exitsString(self):
- rstring = "Possible exits: "
- rstring.append(", ".join(list(self.getExits().keys())))
- return rstring
- def getExits(self):
- return self.exits
- def getExitDirection(self, direction):
- if direction in self.exits:
- if self.exits[direction]:
- return self.exits[direction]
- else:
- print "There is no exit in that direction"
- return None
- else:
- print "%s is not a direction" % direction
- #item methods
- def addItem(self, item):
- self.inventory.append(item)
- def takeItem(self, item):
- self.inventory.remove(item)
Advertisement
Add Comment
Please, Sign In to add comment