D10d3 icon

engine.py

D10d3 | PRO | 11/14/16 01:24:29 AM UTC | 0 ⭐ | 439 👁️ | Never ⏰ | []
Python |

2.44 KB

|

None

|

0 👍

/

0 👎

#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)

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎