Exemple #1
0
        AvailableMove PressedOnAvailableMove(ChessBoardNode nodePressed)
        {
            foreach (AvailableMove move in availableMoves)
            {
                if (move.node == nodePressed)
                {
                    return(move);
                }
            }

            return(new AvailableMove(null));
        }
Exemple #2
0
        void ResetBoard()
        {
            if (chessBoardNodeArray != null) //Clear all buttons from previos play
            {
                List <Button> buttons = ChessBoard.Controls.OfType <Button>().ToList();
                foreach (Button b in buttons)
                {
                    ChessBoard.Controls.Remove(b);
                    b.Dispose();
                }
            }

            chessBoardNodeArray = new ChessBoardNode[8, 8];

            moveColor      = ChessPieceColor.White;
            MoveLabel.Text = moveColor.ToString();

            for (int x = 0; x < 8; x++) //Spawn ned buttons and set them up
            {
                for (int y = 0; y < 8; y++)
                {
                    Button newChessButton = new Button();
                    ChessBoard.Controls.Add(newChessButton);
                    newChessButton.Location = new Point(x * 50, y * 50);
                    newChessButton.Width    = 50;
                    newChessButton.Height   = 50;

                    chessBoardNodeArray[x, y] = new ChessBoardNode(x, y, newChessButton);
                    newChessButton.Click     += new EventHandler(onButtonPressed);
                }
            }


            //Set all starting pieces
            for (int x = 0; x < 8; x++) //Set pawns
            {
                SpawnChessPiece(x, 1, ChessPieceColor.White, typeof(CPPawn));
                SpawnChessPiece(x, 6, ChessPieceColor.Black, typeof(CPPawn));
            }


            SpawnChessPiece(0, 0, ChessPieceColor.White, typeof(CPRook));
            SpawnChessPiece(7, 0, ChessPieceColor.White, typeof(CPRook));
            SpawnChessPiece(0, 7, ChessPieceColor.Black, typeof(CPRook));
            SpawnChessPiece(7, 7, ChessPieceColor.Black, typeof(CPRook));

            SpawnChessPiece(1, 0, ChessPieceColor.White, typeof(CPKnight));
            SpawnChessPiece(6, 0, ChessPieceColor.White, typeof(CPKnight));
            SpawnChessPiece(1, 7, ChessPieceColor.Black, typeof(CPKnight));
            SpawnChessPiece(6, 7, ChessPieceColor.Black, typeof(CPKnight));

            SpawnChessPiece(2, 0, ChessPieceColor.White, typeof(CPBishop));
            SpawnChessPiece(5, 0, ChessPieceColor.White, typeof(CPBishop));
            SpawnChessPiece(2, 7, ChessPieceColor.Black, typeof(CPBishop));
            SpawnChessPiece(5, 7, ChessPieceColor.Black, typeof(CPBishop));

            SpawnChessPiece(3, 0, ChessPieceColor.White, typeof(CPQueen));
            SpawnChessPiece(3, 7, ChessPieceColor.Black, typeof(CPQueen));

            SpawnChessPiece(4, 0, ChessPieceColor.White, typeof(CPKing));
            SpawnChessPiece(4, 7, ChessPieceColor.Black, typeof(CPKing));
        }
Exemple #3
0
 public AvailableMove(ChessBoardNode _node, MoveType _moveType = MoveType.MoveAndAttack)
 {
     node     = _node;
     moveType = _moveType;
 }
Exemple #4
0
        void ResetBoard()
        {
            if (chessBoardNodeArray != null) //Clear all buttons from previos play
            {
                List <Button> buttons = ChessBoard.Controls.OfType <Button>().ToList();
                foreach (Button b in buttons)
                {
                    ChessBoard.Controls.Remove(b);
                    b.Dispose();
                }
            }

            chessBoardNodeArray = new ChessBoardNode[8, 8];

            moveColor      = ChessPieceColor.White;
            MoveLabel.Text = moveColor.ToString();

            for (int x = 0; x < 8; x++) //Spawn ned buttons and set them up
            {
                for (int y = 0; y < 8; y++)
                {
                    Button newChessButton = new Button();
                    ChessBoard.Controls.Add(newChessButton);
                    newChessButton.Location = new Point(x * 50, y * 50);
                    newChessButton.Width    = 50;
                    newChessButton.Height   = 50;

                    chessBoardNodeArray[x, y] = new ChessBoardNode(x, y, newChessButton);
                    newChessButton.Click     += new EventHandler(onButtonPressed);
                }
            }


            //Set all starting pieces
            for (int x = 0; x < 8; x++) //Set pawns
            {
                chessBoardNodeArray[x, 1].ChangePiece(ChessPiece.Pawn, ChessPieceColor.White);
                chessBoardNodeArray[x, 6].ChangePiece(ChessPiece.Pawn, ChessPieceColor.Black);
            }

            chessBoardNodeArray[0, 0].ChangePiece(ChessPiece.Rook, ChessPieceColor.White);
            chessBoardNodeArray[7, 0].ChangePiece(ChessPiece.Rook, ChessPieceColor.White);
            chessBoardNodeArray[0, 7].ChangePiece(ChessPiece.Rook, ChessPieceColor.Black);
            chessBoardNodeArray[7, 7].ChangePiece(ChessPiece.Rook, ChessPieceColor.Black);

            chessBoardNodeArray[1, 0].ChangePiece(ChessPiece.Knight, ChessPieceColor.White);
            chessBoardNodeArray[6, 0].ChangePiece(ChessPiece.Knight, ChessPieceColor.White);
            chessBoardNodeArray[1, 7].ChangePiece(ChessPiece.Knight, ChessPieceColor.Black);
            chessBoardNodeArray[6, 7].ChangePiece(ChessPiece.Knight, ChessPieceColor.Black);

            chessBoardNodeArray[2, 0].ChangePiece(ChessPiece.Bishop, ChessPieceColor.White);
            chessBoardNodeArray[5, 0].ChangePiece(ChessPiece.Bishop, ChessPieceColor.White);
            chessBoardNodeArray[2, 7].ChangePiece(ChessPiece.Bishop, ChessPieceColor.Black);
            chessBoardNodeArray[5, 7].ChangePiece(ChessPiece.Bishop, ChessPieceColor.Black);

            chessBoardNodeArray[3, 0].ChangePiece(ChessPiece.Queen, ChessPieceColor.White);
            chessBoardNodeArray[3, 7].ChangePiece(ChessPiece.Queen, ChessPieceColor.Black);

            chessBoardNodeArray[4, 0].ChangePiece(ChessPiece.King, ChessPieceColor.White);
            chessBoardNodeArray[4, 7].ChangePiece(ChessPiece.King, ChessPieceColor.Black);
        }