def playerAction(): global corNumberX global corNumberY global direction witch() print("You are at X:" + str(corNumberX) + " Y:" + str(corNumberY)) playerInput = raw_input("> ").lower() if playerInput == "north": if corNumberY == 10: if corNumberX == 3: print "You need a key to go in there." time.sleep(1.5) playerAction() else: print "You can't go there! Those are the dungeon walls." time.sleep(1.5) playerAction() corNumberY = corNumberY + 1 monsterEncounter() hidden_treasure() playerAction() elif playerInput == "south": # Yeah! Go 'elif'! if corNumberY == 0: print "Don't be silly! You still have a princess to save!" time.sleep(1.5) playerAction() else: corNumberY = corNumberY - 1 monsterEncounter() hidden_treasure() playerAction() elif playerInput == "east": if corNumberX == 10: print "Whoa! You almost fell of the cliff!" time.sleep(1.5) playerAction() else: corNumberX = corNumberX + 1 monsterEncounter() hidden_treasure() playerAction() elif playerInput == "west": if corNumberX == 0: print "You don't want to go in there! That forest doesn't have anything in it" time.sleep(1) playerAction() else: corNumberX = corNumberX - 1 monsterEncounter() hidden_treasure() playerAction() elif playerInput == "stats": showInventory() # This function is defined in the 'inventory.py' file. playerAction() elif playerInput == "store": store() playerAction() elif playerInput == "exitgame": print("Are you sure you want to quit? ('yes' or 'no')") exitConfirm = raw_input("> ") if exitConfirm == "yes": print("Exiting the game...") time.sleep(1) print( "GAME OVER -- I don't see why they used you to save the princess." ) time.sleep(3) exit() elif exitConfirm == "no": print("Will not exit the game.") playerAction() else: print("Invalid answer.") print("Will not exit the game.") playerAction() elif playerInput == "inventory".lower(): showStats() playerAction() elif playerInput == "help": playerAction() if playerInput == "map".lower(): global map global mapX global mapY if map == True: print "" print " Go to X:" + str(mapX) + " Y:" + str(mapY) print "" time.sleep(1) playerAction() else: print " You don't have the map" else: print("Invalid command.") playerAction()
def handleMovement(player, key, level): global inputState keyChar = chr(key.c) if key.vk != 65: keyChar = getUnprintableKeypress(key) if keyChar == 'j': if level.floor[player.Z][player.X][player.Y + 1].isPassable(): player.Y += 1 return True elif level.floor[player.Z][player.X][player.Y + 1].entity is not None: entity.attack(player, level.floor[player.Z][player.X][player.Y + 1].entity) messager.addAttackMessage(level.floor[player.Z][player.X][player.Y + 1].entity) return True else: messager.addMessage("You can't pass through here.") return False if keyChar == 'k': if level.floor[player.Z][player.X][player.Y - 1].isPassable(): player.Y -= 1 return True elif level.floor[player.Z][player.X][player.Y - 1].entity is not None: entity.attack(player, level.floor[player.Z][player.X][player.Y - 1].entity) messager.addAttackMessage(level.floor[player.Z][player.X][player.Y - 1].entity) return True else: messager.addMessage("You can't pass through here.") return False if keyChar == 'h': if level.floor[player.Z][player.X - 1][player.Y].isPassable(): player.X -= 1 return True elif level.floor[player.Z][player.X - 1][player.Y].entity is not None: entity.attack(player, level.floor[player.Z][player.X - 1][player.Y].entity) messager.addAttackMessage(level.floor[player.Z][player.X - 1][player.Y].entity) return True else: messager.addMessage("You can't pass through here.") return False if keyChar == 'l': if level.floor[player.Z][player.X + 1][player.Y].isPassable(): player.X += 1 return True elif level.floor[player.Z][player.X + 1][player.Y].entity is not None: entity.attack(player, level.floor[player.Z][player.X + 1][player.Y].entity) messager.addAttackMessage(level.floor[player.Z][player.X + 1][player.Y].entity) return True else: messager.addMessage("You can't pass through here.") return False if keyChar == '>' and level.floor[player.Z][player.X][player.Y].terrain == dungeon.stairdown: player.Z += 1 messager.addMessage("You go down the steps...") return True if keyChar == '<' and level.floor[player.Z][player.X][player.Y].terrain == dungeon.stairup: messager.addMessage("You go up the steps...") player.Z -= 1 return True if keyChar == 'q': exit() if keyChar == 's': util.saveGame(level, player, None) exit() if keyChar == 'i': inventory.showInventory(player) inputState = inventoryDisplay return False if keyChar == ',': theItems = level.floor[player.Z][player.X][player.Y].items if not theItems: return False for i, v in theItems.iteritems(): player.giveItem(i, v) level.floor[player.Z][player.X][player.Y].items = {} return True if keyChar == 'd': inputState = stateDrop messager.addMessage("Drop what item?") return False if keyChar == 'w': inputState = wieldPrompt messager.addMessage("Wield what item?") if keyChar == 'W': inputState = wearPrompt messager.addMessage("Wear what item?") return False