コード例 #1
0
ファイル: ai.py プロジェクト: tacoman/MadNet-Zero
def enemyTurn(dungeon, player, enemy):
    global pathFoundRooms
    if player.Z != enemy.Z:
        return # Do nothing if on different floor
    # Is player adjacent? If so, attack!
    if areAdjacent(player, enemy):
        entity.attack(enemy, player)
        if enemy.name == "":
            messager.addMessage("The enemy attacks!")
        else:
            messager.addMessage(enemy.name + " attacks!")
        return
    # Else, run pathfinding, then move
    dest = findPath(dungeon, player, enemy)
    X, Y, Z = dest.X, dest.Y, dest.Z
    oldX, oldY, oldZ = enemy.X, enemy.Y, enemy.Z
    if X == oldX and Y == oldY and Z == oldZ:
        print "Staying put."
    elif not dungeon.floor[Z][X][Y].enterEntity(enemy):
        print X, Y, Z
        print dungeon.floor[Z][X][Y].entity
        print "ERROR: ENEMY MOVEMENT FAILED!"
    else:
        dungeon.floor[oldZ][oldX][oldY].entity = None
        enemy.X, enemy.Y, enemy.Z = X, Y, Z
    clearCells(pathFoundRooms)
コード例 #2
0
ファイル: input.py プロジェクト: tacoman/MadNet-Zero
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