示例#1
0
        public ChessBoard() : base(8, 8)
        {
            ConsoleColor[] colors = { ConsoleColor.Black, ConsoleColor.White };

            /*
             * "I'M SO FANCY, YOU ALREADY KNOW"
             * AN USELESS BUT COOL WAY OF INITIALIZING THE BOARD WITH PIECES USING FOR LOOPS
             */
            for (int team = 0; team < 2; team++)
            {
                for (int y = 0; y < 2; y++)
                {
                    int mirrorY = Math.Abs((7 * team) - y);
                    for (int x = 0; x < 4; x++)
                    {
                        switch (y)
                        {
                        case 0:
                            switch (x)
                            {
                            case 0:
                                _tiles[x, mirrorY]     = new PieceRook(colors[team], this, new Position(x, mirrorY));
                                _tiles[7 - x, mirrorY] = new PieceRook(colors[team], this, new Position(7 - x, mirrorY));
                                break;

                            case 1:
                                _tiles[x, mirrorY]     = new PieceKnight(colors[team], this, new Position(x, mirrorY));
                                _tiles[7 - x, mirrorY] = new PieceKnight(colors[team], this, new Position(7 - x, mirrorY));
                                break;

                            case 2:
                                _tiles[x, mirrorY]     = new PieceBishop(colors[team], this, new Position(x, mirrorY));
                                _tiles[7 - x, mirrorY] = new PieceBishop(colors[team], this, new Position(7 - x, mirrorY));
                                break;

                            case 3:
                                _tiles[x, mirrorY]     = new PieceQueen(colors[team], this, new Position(x, mirrorY));
                                _tiles[7 - x, mirrorY] = new PieceKing(colors[team], this, new Position(7 - x, mirrorY));
                                break;
                            }
                            break;

                        case 1:
                            _tiles[x, mirrorY]     = new PiecePawn(colors[team], this, new Position(x, mirrorY));
                            _tiles[7 - x, mirrorY] = new PiecePawn(colors[team], this, new Position(7 - x, mirrorY));
                            break;
                        }
                    }
                }
            }
        }
示例#2
0
        public Board Create()
        {
            try {
                int countNroSquare = 0;

                #region Square
                for (int i = 1; i < nroColumn + 1; i++)
                {
                    if (countNroSquare == 0 || countNroSquare == 16 ||
                        countNroSquare == 32 || countNroSquare == 48 || countNroSquare == 64)
                    {
                        colorSquare = colorSquareD;
                    }
                    if (countNroSquare == 8 || countNroSquare == 24 ||
                        countNroSquare == 40 || countNroSquare == 56)
                    {
                        colorSquare = colorSquareL;
                    }

                    foreach (string item in Row)
                    {
                        Square squareiitem = new Square
                        {
                            Name      = "square" + i + item,
                            PositionY = i.ToString(),
                            PositionX = item,
                            Color     = colorSquare,
                            Empty     = true
                        };

                        squareList.Add(squareiitem);

                        if (colorSquare == colorSquareD)
                        {
                            colorSquare = colorSquareL;
                        }
                        else
                        {
                            colorSquare = colorSquareD;
                        }

                        countNroSquare++;
                    }
                }
                #endregion

                #region Piece

                #region Pawn
                for (int p = 1; p < ((nroColumn * 2) + 1); p++)
                {
                    if (nroColumn >= p)
                    {
                        //create piece Pawn Black
                        PiecePawn pawnpcolorB = new PiecePawn
                        {
                            Name  = "pawn" + p + colorB,
                            Color = colorB,
                            Dead  = false,
                            Img   = "♟",
                        };

                        pieceList.Add(pawnpcolorB);
                    }
                    else
                    {
                        var aux = (p - nroColumn);
                        //create piece Pawn White
                        PiecePawn pawnauxcolorW = new PiecePawn
                        {
                            Name  = "pawn" + aux + colorW,
                            Color = colorW,
                            Dead  = false,
                            Img   = "♙",
                        };

                        pieceList.Add(pawnauxcolorW);
                    }
                }
                #endregion

                #region Tower
                //create piece Tower Black
                PieceTower tower1colorB = new PieceTower
                {
                    Name  = "tower1" + colorB,
                    Color = colorB,
                    Dead  = false,
                    Img   = "♜",
                };

                PieceTower tower2colorB = new PieceTower
                {
                    Name  = "tower2" + colorB,
                    Color = colorB,
                    Dead  = false,
                    Img   = "♜",
                };

                pieceList.Add(tower1colorB);
                pieceList.Add(tower2colorB);

                //create piece Tower White
                PieceTower tower1colorW = new PieceTower
                {
                    Name  = "tower1" + colorW,
                    Color = colorW,
                    Dead  = false,
                    Img   = "♖",
                };

                PieceTower tower2colorW = new PieceTower
                {
                    Name  = "tower2" + colorW,
                    Color = colorW,
                    Dead  = false,
                    Img   = "♖",
                };

                pieceList.Add(tower1colorW);
                pieceList.Add(tower2colorW);
                #endregion

                #region Bishop
                //create piece Bishop Black
                PieceBishop bishop1colorB = new PieceBishop
                {
                    Name  = "bishop1" + colorB,
                    Color = colorB,
                    Dead  = false,
                    Img   = "♝",
                };

                PieceBishop bishop2colorB = new PieceBishop
                {
                    Name  = "bishop2" + colorB,
                    Color = colorB,
                    Dead  = false,
                    Img   = "♝",
                };

                pieceList.Add(bishop1colorB);
                pieceList.Add(bishop2colorB);

                //create piece Bishop White
                PieceBishop bishop1colorW = new PieceBishop
                {
                    Name  = "bishop1" + colorW,
                    Color = colorW,
                    Dead  = false,
                    Img   = "♗",
                };

                PieceBishop bishop2colorW = new PieceBishop
                {
                    Name  = "bishop2" + colorW,
                    Color = colorW,
                    Dead  = false,
                    Img   = "♗",
                };

                pieceList.Add(bishop1colorW);
                pieceList.Add(bishop2colorW);

                #endregion Bishop

                #region Horse
                //create piece Horse Black
                PieceHorse horse1colorB = new PieceHorse
                {
                    Name  = "horse1" + colorB,
                    Color = colorB,
                    Dead  = false,
                    Img   = "♞",
                };

                PieceHorse horse2colorB = new PieceHorse
                {
                    Name  = "horse2" + colorB,
                    Color = colorB,
                    Dead  = false,
                    Img   = "♞",
                };

                pieceList.Add(horse1colorB);
                pieceList.Add(horse2colorB);

                //create piece Horse White
                PieceHorse horse1colorW = new PieceHorse
                {
                    Name  = "horse1" + colorW,
                    Color = colorW,
                    Dead  = false,
                    Img   = "♘",
                };

                PieceHorse horse2colorW = new PieceHorse
                {
                    Name  = "horse2" + colorW,
                    Color = colorW,
                    Dead  = false,
                    Img   = "♘",
                };

                pieceList.Add(horse1colorW);
                pieceList.Add(horse2colorW);

                #endregion

                #region Queen
                //create piece queen Black
                PieceQueen queencolorB = new PieceQueen
                {
                    Name  = "queen" + colorB,
                    Color = colorB,
                    Dead  = false,
                    Img   = "♛",
                };

                pieceList.Add(queencolorB);

                //create piece queen White
                PieceKing queencolorW = new PieceKing
                {
                    Name  = "queen" + colorW,
                    Color = colorW,
                    Dead  = false,
                    Img   = "♕",
                };

                pieceList.Add(queencolorW);
                #endregion

                #region King
                //create piece king Black
                PieceKing kingcolorB = new PieceKing
                {
                    Name  = "king" + colorB,
                    Color = colorB,
                    Dead  = false,
                    Img   = "♚",
                };

                pieceList.Add(kingcolorB);

                //create piece king White
                PieceKing kingcolorW = new PieceKing
                {
                    Name  = "king" + colorW,
                    Color = colorW,
                    Dead  = false,
                    Img   = "♔",
                };

                pieceList.Add(kingcolorW);
                #endregion

                #endregion

                newBoard.Squares = squareList;
                newBoard.Pieces  = pieceList;

                newBoard = RandomPieces(newBoard);

                return(newBoard);
            }
            catch (Exception ex) { return(null); }
        }