Example #1
0
def moveEntity(level: Level, name: str, currBoard: int,
               destination: tuple, isPlayer: bool):
    board = level.boards[currBoard]
    entity = board.players[name] if isPlayer else board.enemies[name]
    destInBoard = locationInBounds(destination, board.origin,
                                   board.dimensions)

    if destInBoard:
        entity.location = destination
    else:
        boardEntities = board.players if isPlayer else board.enemies
        del boardEntities[name]
        for i in range(len(level.boards)):
            otherBoard = level.boards[i]
            if locationInBounds(destination, otherBoard.origin,
                                otherBoard.dimensions):
                entity.location = destination

                if isPlayer:
                    otherBoard.players[name] = entity
                else:
                    otherBoard.enemies[name] = entity
                level.currBoard = i
                break

    return level
Example #2
0
def moveEntity(level: Level, name: str, currBoard: int, newBoardNum: int,
               destination: tuple, isPlayer: bool):
    """
    Move the Player/Enemy with the given name to the given destination
    in the level.
    :param level: Level
    :param name: str
    :param currBoard: int
    :param newBoardNum: int
    :param destination: tuple
    :param isPlayer: bool
    """
    board = level.boards[currBoard]
    entity = getPlayer(level, name) if isPlayer else getEnemy(level, name)
    destInBoard = locationInBounds(destination, board.origin, board.dimensions)

    if destInBoard:
        entity.location = destination
    else:
        boardEntities = board.players if isPlayer else board.enemies
        del boardEntities[name]
        if newBoardNum != -1:
            otherBoard = level.boards[newBoardNum]
            entity.location = destination

            if isPlayer:
                otherBoard.players[name] = entity
            else:
                otherBoard.enemies[name] = entity

            level.currBoard = newBoardNum

    return level
Example #3
0
def playerPossibleCardinalMoves(location: tuple, numMoves: int, level: Level,
                                boardNumber: int):
    """
    Outputs the possible moves for a player given the number of cardinal moves.
    :param location: tuple
    :param numMoves: int
    :param level: Level
    :param boardNumber: int
    """
    board = level.boards[boardNumber]
    possibleMoves = []
    while numMoves > 0:
        if len(possibleMoves) == 0:
            possibleMoves += list(filter(
                lambda lamLoc: locationInLevelBounds(level, lamLoc),
                getLocationsAround(location)))
        else:
            temp = []
            for loc in possibleMoves:
                temp += list(filter(
                    lambda lamLoc: locationInBounds(lamLoc, board.origin,
                                                    board.dimensions),
                    getLocationsAround(loc)))
            possibleMoves += temp
        numMoves -= 1
        possibleMoves = list(unique_everseen(possibleMoves))

    return possibleMoves
Example #4
0
def enemyPossibleMoves(enemy: Enemy, game: Dungeon):
    """
    Gets a list of the possible moves a given enemy can feasibly make.
    In essence, gets all the moves are traversable within each enemy's
    walkable distance.
    :params enemy: Enemy
    :params game: Dungeon
    """
    possibleMoves = []
    enemyBoardNum = whichBoardInLevel(game.levels[game.currLevel],
                                      enemy.location)
    enemyBoard: Board = game.levels[game.currLevel].boards[enemyBoardNum]
    if enemy.enemyType == "zombie":
        tilesAround = getLocationsAround(enemy.location)
        for loc in tilesAround:
            if locationInBounds(loc, enemyBoard.origin, enemyBoard.dimensions):
                tile = enemyBoard.tiles[loc[0]][loc[1]]
                if tile.tileType != TileEnum.WALL and tile.tileType != TileEnum.DOOR:
                    possibleMoves.append(loc)
    elif enemy.enemyType == "ghost":
        tilesAround = getLocationsAround(enemy.location)
        for loc in tilesAround:
            if locationInLevelBounds(game.levels[game.currLevel], loc):
                possibleMoves.append(loc)
    return possibleMoves
Example #5
0
def whichBoardInLevel(level: Level, givenPoint: tuple):
    pointX = int(givenPoint[0])
    pointY = int(givenPoint[1])
    point = (pointX, pointY)
    for i in range(len(level.boards)):
        currBoard: Board = level.boards[i]
        if currBoard.boardType == BoardEnum.ROOM:
            if locationInBounds(point, currBoard.origin, currBoard.dimensions):
                return i
        else:
            hallwayTiles = currBoard.tiles
            if first_true(hallwayTiles, default=None,
                          pred=lambda tile: tile.location == point) is not None:
                return i
    return -1