Exemplo n.º 1
0
        /// <summary>
        /// Call this before using the chess board
        /// </summary>
        public void CreateBoard(bool isPlayerWhite, ChessHalfSet whiteSet, ChessHalfSet blackSet)
        {
            // rotate chessboard 180 deg
            if (!isPlayerWhite)
            {
                transform.Rotate(0, 0, 180, Space.Self);
            }

            // create tiles
            tiles = new Tile[BoardSize, BoardSize];

            for (int x = 0; x < BoardSize; x++)
            {
                for (int y = 0; y < BoardSize; y++)
                {
                    var go = InstantiatePrefabAt(tilePrefab, new Vector2Int(x, y));

                    var tile = go.GetComponent <Tile>();
                    tile.IsWhite  = (x % 2 == 0) ^ (y % 2 == 0);
                    tile.Position = new Vector2Int(x, y);
                    tile.OnClick += TileClicked;

                    tiles[x, y] = tile;
                }
            }

            // place pieces
            pieces = new List <Piece>();

            // white
            for (int i = 0; i < BoardSize; i++)
            {
                CreatePiece(i, 1, whiteSet.pawns[i]);
            }

            CreatePiece(0, 0, whiteSet.leftRook);
            CreatePiece(1, 0, whiteSet.leftKnight);
            CreatePiece(2, 0, whiteSet.leftBishop);
            CreatePiece(3, 0, whiteSet.queen);
            CreatePiece(4, 0, whiteSet.king);
            CreatePiece(5, 0, whiteSet.rightBishop);
            CreatePiece(6, 0, whiteSet.rightKnight);
            CreatePiece(7, 0, whiteSet.rightRook);

            // black
            for (int i = 0; i < BoardSize; i++)
            {
                CreatePiece(i, 6, blackSet.pawns[i]);
            }

            CreatePiece(0, 7, blackSet.leftRook);
            CreatePiece(1, 7, blackSet.leftKnight);
            CreatePiece(2, 7, blackSet.leftBishop);
            CreatePiece(3, 7, blackSet.queen);
            CreatePiece(4, 7, blackSet.king);
            CreatePiece(5, 7, blackSet.rightBishop);
            CreatePiece(6, 7, blackSet.rightKnight);
            CreatePiece(7, 7, blackSet.rightRook);
        }
Exemplo n.º 2
0
        public static ChessSet CreateDefaultSet()
        {
            var set = new ChessSet();

            set.whiteHalf = ChessHalfSet.CreateDefaultHalfSet(PieceColor.White);
            set.blackHalf = ChessHalfSet.CreateDefaultHalfSet(PieceColor.Black);
            return(set);
        }
Exemplo n.º 3
0
        ///////////////////
        // Game starting //
        ///////////////////

        /// <summary>
        /// Start playground for debugging (when launched right
        /// away from unity editor)
        /// </summary>
        private void StartDebug()
        {
            Debug.LogWarning("No startup match provided, creating a " +
                             "debugging match against the computer.");

            var match = new MatchEntity()
            {
                WhitePlayer    = Auth.Player,
                WhitePlayerSet = ChessHalfSet.CreateDefaultHalfSet(
                    PieceColor.White
                    ),

                BlackPlayer    = null,
                BlackPlayerSet = ChessHalfSet.CreateDefaultHalfSet(
                    PieceColor.Black
                    )
            };

            StartRegular(match);
        }