Beispiel #1
0
 private void PlaceWalls(Board.Tile tile)
 {
     PlaceWall(tile, Constants.Direction.Left);
     PlaceWall(tile, Constants.Direction.Right);
     PlaceWall(tile, Constants.Direction.Top);
     PlaceWall(tile, Constants.Direction.Bot);
 }
Beispiel #2
0
    private Piece PlacePieceImpl(Player player, int pieceId, PieceType type, TilePos position)
    {
        Board.Tile tile = board.GetTile(position);
        if (tile.occupied)
        {
            return(null);
        }
        if (pieceId < 0)
        {
            // Local piece, pick new ID
            // FIXME - This doesn't work; both players will have a different counter
            pieceId = nextFreePieceId++;
        }
        var piece = new Piece {
            id = pieceId, owner = player, type = type, position = position
        };

        pieces.Add(pieceId, piece);
        board.SetTileOccupied(position, true);

        // Instantiate game object for piece
        GameObject pieceGO = CharacterManager.instance.Instantiate(type);

        pieceGO.transform.position = board.GetPosition(position);
        piece.gameObject           = pieceGO;

        return(piece);
    }
Beispiel #3
0
    private void BuildPathNextTo(IntVector2 position)
    {
        // If we're standing on the target, find the neighbor with the lowest
        // movement cost and move into it.
        if (this.position == position)
        {
            Board.Tile tile   = BoardManager.Board.GetTile(position);
            Board.Tile moveTo = null;
            foreach (Board.Tile neighbor in tile.GetNeighbors())
            {
                if (
                    moveTo == null ||
                    moveTo.GetHinderance() > neighbor.GetHinderance()
                    )
                {
                    moveTo = neighbor;
                }
            }

            if (moveTo.GetHinderance() < AStarResolver.MAX_COST)
            {
                path = new Queue <IntVector2>();
                path.Enqueue(moveTo.position);
            }
        }
        else
        {
            BuildPathTo(position);
            RemoveLastPathItem();
        }
    }
Beispiel #4
0
    private TileController GetTileController(Board.Tile tile)
    {
        // Figure out where this tile exists within our displayed board. Assuming
        // the tile is currently displayed we know its grid position will be
        // right of (tile.x > TL.x) and below (tile.y < TL.y) the top-left tile.
        TileController topLeft = displayTiles[tileTL.x, tileTL.y];
        int            xOffset = tile.position.x - topLeft.gridPosition.x; // Positive
        int            yOffset = tile.position.y - topLeft.gridPosition.y; // Negative

        if (
            xOffset < 0 || xOffset > displayWidth ||
            yOffset > 0 || yOffset < -displayHeight
            )
        {
            // This tile is not being displayed, thus we don't have a tile
            // controller for it at this time.
            return(null);
        }

        // Now we know our grid offset, so calculate our display offset,
        // adjusting for wrapping around the display board.
        int displayX = (topLeft.displayPosition.x + xOffset) % displayWidth;
        int displayY = (topLeft.displayPosition.y + yOffset + displayHeight) % displayHeight;

        // And viola, we have a tile controller.
        return(displayTiles[displayX, displayY]);
    }
Beispiel #5
0
    /// <summary>
    /// Sets the visual representation of the Tile according to the roomType
    /// Called by InitBoard and PlaceTile.
    /// </summary>
    /// <param name="tile"></param>
    public GameObject PlaceTileGameObject(Board.Tile tile)
    {
        int x = tile.pos_x;
        int y = tile.pos_y;

        if (tile.gFloor != null)
        {
            GameObject.Destroy(tile.gFloor);
        }

        GameObject g = CreateTileGameObject(tile.data.roomType, tile.data.connected, tile.data.player);

        g.name = "Tile_X" + x + "Y" + y;
        g.SetActive(tile.data.roomType != Board.ROOM_TYPE.EMPTY);
        g.transform.parent        = boardContainer;
        g.transform.localPosition = new Vector3(x + 0.5f, tileDatabase.boardHeight, y + 0.5f);

        tile.gFloor = g;

        if (tile.data.roomType == Board.ROOM_TYPE.WALL)
        {
            if (tile.gProp != null)
            {
                GameObject.Destroy(tile.gProp);
            }
            GameObject block = GameObject.Instantiate(tileDatabase.prefabWallBlock, boardContainer);
            block.name = "Tile_X" + x + "Y" + y + "Block";
            block.transform.localPosition = new Vector3(x + 0.5f, tileDatabase.boardHeight + 0.25f, y + 0.5f);
            tile.gProp = block;
        }

        return(g);
    }
Beispiel #6
0
    private bool IsDisplayed(Board.Tile tile)
    {
        IntVector2 topLeft     = displayTiles[tileTL.x, tileTL.y].gridPosition;
        IntVector2 bottomRight = displayTiles[tileBR.x, tileBR.y].gridPosition;

        return(tile.position.IsBetween(topLeft, bottomRight));
    }
Beispiel #7
0
    void SetPlayerStartTiles(int player_id)
    {
        int start_x = 0;
        int start_y = 0;

        PlayerController pc = players[player_id];

        if (player_id == 0 || player_id == 1)
        {
            start_y = (int)(boardHeight * 0.5);
        }
        if (player_id == 2 || player_id == 3)
        {
            start_x = (int)(boardWidth * 0.5);
        }
        if (player_id == 1)
        {
            start_x = boardWidth - 1;
        }
        if (player_id == 3)
        {
            start_y = boardHeight - 1;
        }

        pc.startX = start_x;
        pc.startY = start_y;

        Board.Tile tile = board.GetTile(start_x, start_y);
        tile.data.player   = player_id;
        tile.data.roomType = Board.ROOM_TYPE.START;
    }
Beispiel #8
0
 /// <summary>
 /// Places a Tile by setting the board logical state, and placing the visual representation.
 /// </summary>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <param name="tileState"></param>
 public void PlaceTile(int x, int y, Board.ROOM_TYPE roomState, int player_id, int block_id)
 {
     Board.Tile tile = board.GetTile(x, y);
     tile.data.roomType = roomState;
     tile.data.player   = player_id;
     tile.block_id      = block_id;
     PlaceTileGameObject(tile);
 }
Beispiel #9
0
 public TileEvent(TileEventType type, Board.Tile tile) :
     base(EventType.TileEvent)
 {
     this.tileEventType = type;
     this.tile          = tile;
     this.largeItem     = null;
     this.smallItem     = null;
 }
    private ulong GetTileCost(IntVector2 pos)
    {
        Board.Tile tile = board.GetTile(pos);
        if (tile == null)
        {
            return(MAX_COST);
        }

        return(tile.GetHinderance());
    }
Beispiel #11
0
    /// <summary>
    /// Places a block if it fits
    /// </summary>
    /// <returns><c>true</c>, if play block was placed, <c>false</c> otherwise.</returns>
    /// <param name="playBlock">Play block.</param>
    public bool PlacePlayBlock(PlayBlock playBlock, bool erase = false)
    {
        if (CheckPlacePlayBlock(playBlock) == false && !erase)
        {
            return(false);
        }

        int block_id = last_block_id++;
        int startX   = (int)playBlock.transform.position.x;
        int startY   = (int)playBlock.transform.position.z;

        for (int i = 0; i < 4; i++)
        {
            for (int j = 0; j < 4; j++)
            {
                if (playBlock.block.GetValue(i, j) == 0)
                {
                    continue;
                }

                Board.ROOM_TYPE type = playBlock.roomType;
                if (erase)
                {
                    type = Board.ROOM_TYPE.EMPTY;
                }

                PlaceTile(startX + i, startY + j, type, currentPlayerId, block_id);

                //conquer neightbours
                if (mode == GAME_MODE.CONQUEST && !erase)
                {
                    for (int k = 0; k < 4; ++k)
                    {
                        Vector2    offset = offsets[k];
                        Board.Tile next   = board.GetTile(startX + i + (int)offset.x, startY + j + (int)offset.y);
                        if (next == null)
                        {
                            continue;
                        }
                        if (next.data.roomType != Board.ROOM_TYPE.WALL &&
                            next.data.roomType != Board.ROOM_TYPE.EMPTY &&
                            next.data.roomType != Board.ROOM_TYPE.START)
                        {
                            next.data.player   = currentPlayerId;
                            next.data.roomType = type;
                        }
                    }
                }
            }
        }

        GetComponent <AudioSource>().PlayOneShot(clipFall);

        return(true);
    }
    public void MoveTo(IntVector2 gridPos)
    {
        // Update our position in the world.
        gridPosition = gridPos;
        Vector3 newPos = BoardManager.GridToWorldPoint(gridPos);

        newPos.z           = transform.position.z;
        transform.position = newPos;

        // Update the tile and render it.
        tile = BoardManager.Board.GetTile(gridPosition);
        Render();
    }
Beispiel #13
0
    /// <summary>
    /// Updates the full board assets (GameObjects) by reading the tiles roomType
    /// </summary>
    public void UpdateBoardTileAssets()
    {
        if (board == null || board.initialized == false)
        {
            return;
        }

        for (int i = 0; i < boardWidth; i++)
        {
            for (int j = 0; j < boardHeight; j++)
            {
                Board.Tile tile = board.tiles[i, j];
                tile.ClearVisuals();
                //if( tile.data.connected )
                PlaceTileGameObject(tile);
                PlaceWalls(tile);
            }
        }
    }
Beispiel #14
0
        public bool Update()
        {
            // TODO:    Take in an "effort" or "work" amount to subtract from
            //          the job's time-to-completion meter. When meter reaches
            //          zero, job is completed so return true.
            Board.Tile tile = game.board.GetTile(position);
            if (tile.HasLargeItem())
            {
                Debug.LogError(
                    "Dropping job, Tile" + position + " already has large item."
                    );
                return(true); // TODO: Replace with some other status check.
            }

            Item.Wall wall = new Item.Wall(game);
            wall.position = position;
            tile.SetLargeItem(wall);

            return(true);
        }
Beispiel #15
0
    private GameObject PlaceWallProp(Board.Tile tile, Constants.Direction direction, GameObject gPrefab, bool isProp = false)
    {
        if (gPrefab == null)
        {
            return(null);
        }

        GameObject g = CreateWallGameObject(tile.data.roomType, gPrefab);

        g.transform.parent = boardContainer;
        if (isProp)
        {
            GameObject.Destroy(tile.gProp);
            tile.gProp = g;
        }

        if (isProp && !tile.data.connected)
        {
            return(null);
        }

        int x = tile.pos_x;
        int y = tile.pos_y;

        if (direction == Constants.Direction.Bot)
        {
            g.name = "Tile_X" + x + "Y" + y + "WallBot-" + gPrefab.name;
            g.transform.localPosition = new Vector3(x + 0.5f, tileDatabase.boardPropHeight, y + 0.5f);
            if (!isProp)
            {
                tile.gWallBot = g;
            }
        }
        else if (direction == Constants.Direction.Top)
        {
            g.name = "Tile_X" + x + "Y" + y + "WallTop-" + gPrefab.name;
            g.transform.localRotation = Quaternion.Euler(0, 180, 0);
            g.transform.localPosition = new Vector3(x + 0.5f, tileDatabase.boardPropHeight, y + 0.5f);
            if (!isProp)
            {
                tile.gWallTop = g;
            }
        }
        else if (direction == Constants.Direction.Left)
        {
            g.name = "Tile_X" + x + "Y" + y + "WallLeft-" + gPrefab.name;
            g.transform.localRotation = Quaternion.Euler(0, 90, 0);
            g.transform.localPosition = new Vector3(x + 0.5f, tileDatabase.boardPropHeight, y + 0.5f);
            if (!isProp)
            {
                tile.gWallLeft = g;
            }
        }
        else if (direction == Constants.Direction.Right)
        {
            g.name = "Tile_X" + x + "Y" + y + "WallRight-" + gPrefab.name;
            g.transform.localRotation = Quaternion.Euler(0, -90, 0);
            g.transform.localPosition = new Vector3(x + 0.5f, tileDatabase.boardPropHeight, y + 0.5f);
            if (!isProp)
            {
                tile.gWallRight = g;
            }
        }
        g.transform.parent = boardContainer;
        return(g);
    }
Beispiel #16
0
    public GameObject PlaceWall(Board.Tile tile, Constants.Direction direction)
    {
        if (tile.data.roomType == Board.ROOM_TYPE.EMPTY)
        {
            return(null);
        }
        if (tile.data.roomType == Board.ROOM_TYPE.WALL)
        {
            return(null);
        }
        if (tile.data.roomType == Board.ROOM_TYPE.START)
        {
            return(null);
        }

        // Out of bounds checks
        //if(direction == Constants.Direction.Left && tile.pos_x <= 0) return null;
        //else if(direction == Constants.Direction.Right && tile.pos_x >= boardWidth - 1) return null;
        //else if(direction == Constants.Direction.Bot && tile.pos_y <= 0.0f) return null;
        //else if(direction == Constants.Direction.Top && tile.pos_y >= boardHeight - 1) return null;

        // Where will we store the gameObject?
        GameObject targetGO = null;

        Board.Tile targetTile = null;
        int        x          = tile.pos_x;
        int        y          = tile.pos_y;

        if (direction == Constants.Direction.Bot)
        {
            if (y > 0)
            {
                targetTile = board.GetTile(x, y - 1);
            }
            targetGO = tile.gWallBot;
        }
        else if (direction == Constants.Direction.Top)
        {
            if (y < boardHeight - 1)
            {
                targetTile = board.GetTile(x, y + 1);
            }
            targetGO = tile.gWallTop;
        }
        else if (direction == Constants.Direction.Left)
        {
            if (x > 0)
            {
                targetTile = board.GetTile(x - 1, y);
            }
            targetGO = tile.gWallLeft;
        }
        else if (direction == Constants.Direction.Right)
        {
            if (x < boardWidth - 1)
            {
                targetTile = board.GetTile(x + 1, y);
            }
            targetGO = tile.gWallRight;
        }

        if (targetGO != null)
        {
            GameObject.Destroy(targetGO);
        }

        GameObject gPrefab      = tileDatabase.prefabWall;
        bool       isTargetRoom = targetTile != null && targetTile.data.roomType != Board.ROOM_TYPE.WALL && targetTile.data.roomType != Board.ROOM_TYPE.EMPTY;

        if (!isTargetRoom)
        {
            if (x % 2 == 0 && y % 2 == 0)
            {
                PlaceWallProp(tile, direction, tileDatabase.prefabLight, true);
            }
            else
            {
                PlaceWallProp(tile, direction, tileDatabase.RandomWallProp(tile.data.roomType), true);
            }
            if (placeBotWalls == false && direction == Constants.Direction.Bot)
            {
                return(null);
            }
            return(PlaceWallProp(tile, direction, tileDatabase.prefabWall));
        }
        else if (targetTile.data.player != tile.data.player)
        {
            return(PlaceWallProp(tile, direction, tileDatabase.prefabWall));
        }
        else if (targetTile.data.roomType != tile.data.roomType)
        {
            return(PlaceWallProp(tile, direction, tileDatabase.prefabDoor));
        }


        return(null);
    }
Beispiel #17
0
    /// <summary>
    /// Check if a PlayBlock could be placed in the board
    /// Called by the PlayerController to place all the tiles from a new block.
    /// </summary>
    /// <param name="playBlock"></param>
    /// <returns></returns>
    public bool CheckPlacePlayBlock(PlayBlock playBlock)
    {
        int startX = (int)playBlock.transform.position.x;
        int startY = (int)playBlock.transform.position.z;

        bool touching_player = false;
        bool is_corridor     = playBlock.roomType == Board.ROOM_TYPE.CORRIDOR;

        //check if placeable
        for (int i = 0; i < 4; i++)
        {
            for (int j = 0; j < 4; j++)
            {
                int x = startX + i;
                int y = startY + j;
                if (x < 0 || x >= board.boardWidth || y < 0 || y >= board.boardHeight)
                {
                    return(false);
                }
                int has_cell = playBlock.block.GetValue(i, j);
                if (has_cell != 0 && board.GetTileState(x, y) != Board.ROOM_TYPE.EMPTY)
                {
                    Debug.Log("not empty");
                    return(false);
                }
                //check if player id near
                if (!touching_player && has_cell == 1)
                {
                    for (int k = 0; k < 4; ++k)
                    {
                        Vector2 offset = offsets[k];
                        int     x2     = x + (int)offset.x;
                        int     y2     = y + (int)offset.y;
                        if (x2 < 0 || x2 >= board.boardWidth || y2 < 0 || y2 >= boardHeight)
                        {
                            continue; //could happen
                        }
                        Board.Tile tile = board.GetTile(x2, y2);
                        if (tile.data.player == currentPlayerId)
                        {
                            //if not touching a corridor
                            if (force_corridors && tile.data.roomType != playBlock.roomType && (
                                    (is_corridor && tile.data.roomType == Board.ROOM_TYPE.CORRIDOR) ||
                                    (!is_corridor && tile.data.roomType != Board.ROOM_TYPE.CORRIDOR)))
                            {
                                Debug.Log("wrong corridor connection");
                                continue;
                            }

                            if (force_connectivity && !tile.data.connected && tile.data.roomType != Board.ROOM_TYPE.START)
                            {
                                Debug.Log("not connected");
                                continue;
                            }

                            touching_player = true;
                            break;
                        }
                    }
                }
            }
        }

        if (!touching_player) //add tip in GUI about not close to player
        {
            Debug.Log("far from player");
            return(false);
        }

        return(true);
    }