Esempio n. 1
0
        public bool CanBuild(Vector2 builderPosition)
        {
            int x = (int)builderPosition.x;
            int y = (int)builderPosition.y;

            for (int i = 0; i < Board.DIM; i++)
            {
                for (int j = 0; j < Board.DIM; j++)
                {
                    if (i == x && j == y)
                    {
                        continue;
                    }
                    else if (Math.Abs(x - i) <= 1 && Math.Abs(j - y) <= 1)
                    {
                        ITile tile = board[i, j];
                        if (!tile.HasPlayer() && (tile.Height != Height.ROOF))
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
Esempio n. 2
0
        protected void CalculatePossibleBuilds(Vector2 playerPosition)
        {
            int x = (int)playerPosition.x;
            int y = (int)playerPosition.y;

            for (int i = 0; i < Board.DIM; i++)
            {
                for (int j = 0; j < Board.DIM; j++)
                {
                    if (i == x && j == y)
                    {
                        possibleMoves[i, j] = false;
                    }
                    else if (Math.Abs(x - i) <= 1 && Math.Abs(j - y) <= 1)
                    {
                        // Tile tile = Tile.GetTile(i, j);
                        ITile tile = board[i, j];
                        if (!tile.HasPlayer() && (tile.Height != Height.ROOF))
                        {
                            possibleMoves[i, j] = true;
                        }
                    }
                    else
                    {
                        possibleMoves[i, j] = false;
                    }
                }
            }
        }
Esempio n. 3
0
        public bool CanMove(Vector2 /*[]*/ playerPosition /*s*/)
        {
            //for (int k = 0; k < 2; k++)
            //{
            int   x          = (int)playerPosition /*s[k]*/.x;
            int   y          = (int)playerPosition /*s[k]*/.y;
            ITile playerTile = board[x, y];

            for (int i = 0; i < Board.DIM; i++)
            {
                for (int j = 0; j < Board.DIM; j++)
                {
                    if (i == x && j == y)
                    {
                        continue;
                    }
                    else if (Math.Abs(x - i) <= 1 && Math.Abs(j - y) <= 1)
                    {
                        ITile tile = board[i, j];
                        if (tile.HasPlayer() || tile.Height == Height.ROOF || (playerTile.Height + 1).CompareTo(tile.Height) < 0)
                        {
                            continue;
                        }
                        else
                        {
                            return(true);
                        }
                    }
                }
                // }
            }
            return(false);
        }
Esempio n. 4
0
        private int WinValue(IPlayer player)
        {
            int    x        = (int)player.Position.x;
            int    y        = (int)player.Position.y;
            Height height   = board[x, y].Height;
            int    winValue = 0;

            for (int i = 0; i < Board.DIM; i++)
            {
                for (int j = 0; j < Board.DIM; j++)
                {
                    if (i == x && j == y)
                    {
                        continue;
                    }
                    else if (Mathf.Abs(x - i) <= 1 && Mathf.Abs(j - y) <= 1)
                    {
                        ITile tile = board[i, j];
                        if (!tile.HasPlayer() && tile.Height != Height.ROOF && (Mathf.Abs(height - tile.Height) == 1))
                        {
                            winValue++;
                            if (tile.Height == Height.H3)
                            {
                                winValue += 5;
                            }
                        }
                    }
                }
            }
            return(winValue);
        }
Esempio n. 5
0
        protected bool PositioningIsPossible(Vector2 position)
        {
            ITile tile = board[position];

            // the tile is not occupied
            if (!tile.HasPlayer())
            {
                return(true);
            }
            return(false);
        }
Esempio n. 6
0
        protected bool SelectPlayer(Vector2 position)
        {
            int   x            = (int)position.x;
            int   y            = (int)position.y;
            ITile selectedTile = board[x, y];

            if (selectedTile.HasPlayer() && selectedTile.Player.Id == id)
            {
                board.SelectedPlayer = selectedTile.Player;

                // highlight
                CalculatePossibleMoves(board.SelectedPlayer.Position);
                if (board is Board)
                {
                    (board as Board).SetHighlight(possibleMoves);
                }
                return(true);
            }
            return(false);
        }
Esempio n. 7
0
        protected void CalculatePossibleMoves(Vector2 playerPosition)
        {
            int x = (int)playerPosition.x;
            int y = (int)playerPosition.y;

            //Tile playerTile = Tile.GetTile(x, y);
            ITile playerTile = board[x, y];

            for (int i = 0; i < Board.DIM; i++)
            {
                for (int j = 0; j < Board.DIM; j++)
                {
                    if (i == x && j == y)
                    {
                        possibleMoves[i, j] = false;
                    }
                    else if (Math.Abs(x - i) <= 1 && Math.Abs(j - y) <= 1)
                    {
                        //Tile tile = Tile.GetTile(i, j);
                        ITile tile = board[i, j];
                        if (tile.HasPlayer() || tile.Height == Height.ROOF || (playerTile.Height + 1).CompareTo(tile.Height) < 0)
                        {
                            possibleMoves[i, j] = false;
                        }
                        else
                        {
                            possibleMoves[i, j] = true;
                        }
                    }
                    else
                    {
                        possibleMoves[i, j] = false;
                    }
                }
            }
        }
Esempio n. 8
0
        protected bool MovePlayer(Vector2 dstPosition)
        {
            int x = (int)dstPosition.x;
            int y = (int)dstPosition.y;

            IPlayer player  = board.SelectedPlayer;
            ITile   tileSrc = board[board.SelectedPlayer.Position];
            ITile   tileDst = board[x, y];

            if (possibleMoves[x, y])
            {
                if (board is Board)
                {
                    // remove highlight
                    (board as Board).ResetHighlight();
                }
                // remove player from old tile
                tileSrc.Player = null;

                // move player to new tile
                tileDst.Player = player;
                board.SelectedPlayer.Position = dstPosition;
                if (board is Board)
                {
                    Util.MovePlayer(player as Player, x, y, (int)(tileDst.Height - 1));
                }
                //if (!CanBuild(board.SelectedPlayer.Position))
                //{
                //    return false;
                //}

                // set new highlight
                CalculatePossibleBuilds(dstPosition);
                if (board is Board)
                {
                    (board as Board).SetHighlight(possibleMoves);
                }
                return(true);
            }
            else if (tileDst.HasPlayer() && tileDst.Player.Id == id)
            {
                if (board is Board)
                {
                    // remove old highlight
                    (board as Board).ResetHighlight();
                }
                // player wants to select builder again
                board.SelectedPlayer = tileDst.Player;

                // set new highlight
                CalculatePossibleMoves(board.SelectedPlayer.Position);
                if (board is Board)
                {
                    (board as Board).SetHighlight(possibleMoves);
                }
                // move is not over
                return(false);
            }
            else
            {
                // move is not possible, try again
                return(false);
            }
        }