D10d3

engine.py

Nov 13th, 2016
118
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #def room(status):                  #This is the template for each room
  2.     #room = """description"""       #This description is read now and can be printed at will later
  3.     #print room
  4.     #valid = False
  5.     #while not valid:               #This is the command loop, player can keep entering commands at will
  6.         #choice = raw_input ('> ')
  7.         #choice = choice.lower()
  8.         #if "statdebug" in choice:  #A debug routine that let's me see what is in Status while testing
  9.             #print status
  10.         #elif "look" in choice:     #Allows player ro redisplay the description
  11.             #print room
  12.         #elif input:                #Room specific commands
  13.             #bla bla bla
  14.         #else:                      #General error trap for unrecognised commands
  15.             #print "Command not recognized"
  16.     #return status
  17.    
  18.     #room description
  19.     #room exists
  20.     #room inventory
  21.  
  22.  
  23.    
  24. class Room(object):
  25.  
  26.     def __init__(self, name, description):
  27.         self.setName(name)
  28.         self.setDescription(description)
  29.         # Here
  30.         self.exits = {"NORTH": None,
  31.                       "EAST": None,
  32.                       "SOUTH": None,
  33.                       "WEST": None}
  34.         self.inventory = []
  35.    
  36.     def __repr__(self):
  37.         # Return a string that will show up when you print the room
  38.         rstring = self.getName() + "\n"
  39.         rstring += self.getDescription()
  40.         return rstring
  41.         #print MainHall
  42.    
  43.     # Name methods
  44.     def setName(self, name):
  45.         self.name = name + " in cool guy manor"
  46.     def getName(self):
  47.         return self.name
  48.  
  49.     # Description methods
  50.     def setDescription(self, descr):
  51.         self.description = descr
  52.     def getDescription(self):
  53.         return self.description
  54.        
  55.     # exit methods
  56.     def addExit(self, direction, exitRoom):
  57.         self.exits[direction] = exitRoom
  58.     def exitsString(self):
  59.         rstring = "Possible exits: "
  60.         rstring.append(", ".join(list(self.getExits().keys())))
  61.         return rstring
  62.     def getExits(self):
  63.         return self.exits
  64.     def getExitDirection(self, direction):
  65.         if direction in self.exits:
  66.             if self.exits[direction]:
  67.                 return self.exits[direction]
  68.             else:
  69.                 print "There is no exit in that direction"
  70.                 return None
  71.         else:
  72.             print "%s is not a direction" % direction
  73.        
  74.     #item methods
  75.     def addItem(self, item):
  76.         self.inventory.append(item)
  77.     def takeItem(self, item):
  78.         self.inventory.remove(item)
RAW Paste Data