def go(_exit): if _exit == "back": ROOMDB.change(ROOMDB.prevID) print "\nYou retrace your steps..." return ROOMDB.roomID for (counter, txt) in enumerate(ROOMDB.exits): if txt == _exit: if ROOMDB.locks[counter] == 0: _returner = ROOMDB.exitIDs[counter] ROOMDB.change(ROOMDB.exitIDs[counter]) return _returner elif INVENTORY.hasObject(ROOMDB.locks[counter]): print "\nYou unlocked the " + ROOMDB.exits[counter] + " exit with the " + INVENTORY.getObjectWord( ROOMDB.locks[counter] ) + "!\n\n" _returner = ROOMDB.exitIDs[counter] ROOMDB.change(ROOMDB.exitIDs[counter]) return _returner else: return -2 # locked and the user doesn't have the key! return -1 # Room IDs must be >= 0, so -1 indicates
#TODO: refactor if order of command parse for efficiency inp = raw_input(">").lower() #acquire user input and handle if inp == "quit": quit = True success = True elif inp == "exit": #possibly ambiguous command print "If you'd like to stop playing, type 'quit'. If you'd like to exit the room, type 'go ' followed by a room exit." else: words = inp.split() #Array of single words from inp, i.e. ["go", "west", "dumby"] mode = 0 # what command we are interpreting; 0 is not yet recognized or invalid command for (counter, word) in enumerate(words): if mode == 0: #efficiency -- only check this if mode isn't already decided if word == "go" or word == "walk" or word=="north" or word=="south" or word=="east" or word=="west": mode = 1 elif word == "inventory" or word == "inv": INVENTORY.describe() success = True break elif word == "get": mode = 2 elif word == "say" or word == "talk" or word == "hail" or word == "hello" or word == "hi": mode = 9 #conversation time! elif word == "look": success = True print "" print "You examine your surroundings.\n" countdownToLook = 0 elif word == "sudo": mode = -4 if mode == 1: # user is trying to change rooms var = ROOMDB.ROOMDB.go(word)