示例#1
0
    private void ImplementBoardLayout()
    {
        for (int i = 0; i < initialBoardLayout.GetNumberOfPieces(); i++)
        {
            Vector2Int squareIndex = initialBoardLayout.GetChessPieceSquareIndex(i);
            PieceType  pieceType   = initialBoardLayout.GetChessPieceType(i);
            TeamColor  teamColor   = initialBoardLayout.GetChessPieceTeamColor(i);

            CreatePiecePrefabAndInitialize(squareIndex, pieceType, teamColor, Board.ChessGrid, GetChessPlayerFromTeam(teamColor));
        }
    }
示例#2
0
    public void CreateRandomBoardLayout()
    {
        System.Random random          = new System.Random();
        int           numberOfSquares = ChessGridInfo.GRID_SIZE * ChessGridInfo.GRID_SIZE - 1;

        for (int i = 0; i < boardLayout.GetNumberOfPieces(); i++)
        {
            PieceType pieceType = boardLayout.GetChessPieceType(i);
            TeamColor teamColor = boardLayout.GetChessPieceTeamColor(i);

            int         index = random.Next(0, numberOfSquares);
            PieceEntity other = pieceEntities.SingleOrDefault(x =>
                                                              Board.CalculateSquareIndexFromBoardPosition(x.gameObject.transform.position) == squares[index]);
            pieceEntities.Remove(other);
            other?.Die();

            PieceEntity piece = ChessGameController.PieceFactory.CreatePiecePrefab(pieceType.ToString()).GetComponent <PieceEntity>();
            pieceEntities.Add(piece);
            piece.InitializeEntity(Board.CalculateBoardPositionFromSquareIndex(squares[index]), teamColor);
        }
    }