コード例 #1
0
        public void BishopShouldBeIncorrectMove()
        {
            ChessFigure figure = ChessFigure.ConstructByType(FigureType.BISHOP, "C1");

            Assert.AreEqual(false, figure.Move("C3"));
        }
コード例 #2
0
        public void RookShouldBeIncorrectMove()
        {
            ChessFigure figure = ChessFigure.ConstructByType(FigureType.ROOK, "E2");

            Assert.AreEqual(false, figure.Move("C5"));
        }
コード例 #3
0
        public void KnightShouldBeIncorrectMove()
        {
            ChessFigure figure = ChessFigure.ConstructByType(FigureType.KNIGHT, "B1");

            Assert.AreEqual(false, figure.Move("C5"));
        }
コード例 #4
0
        public void QueenShouldBeIncorrectMove()
        {
            ChessFigure figure = ChessFigure.ConstructByType(FigureType.QUEEN, "D1");

            Assert.AreEqual(false, figure.Move("E3"));
        }
コード例 #5
0
        public void FigureMoveToInvalidCoord(string coord)
        {
            ChessFigure figure = ChessFigure.ConstructByType(FigureType.ROOK, "E2");

            Assert.Throws <ArgumentOutOfRangeException>(() => figure.Move(coord));
        }
コード例 #6
0
        public void KingShouldBeIncorrectMove()
        {
            ChessFigure figure = new ChessFigure(ChessFigure.Type.KING, "E1");

            Assert.AreEqual(false, figure.Move("E8"));
        }
コード例 #7
0
        public void QueenShouldBeCorrectMoveDiagonal()
        {
            ChessFigure figure = ChessFigure.ConstructByType(FigureType.QUEEN, "D1");

            Assert.AreEqual(true, figure.Move("H5"));
        }
コード例 #8
0
        public void PawnShouldBeIncorrectMove()
        {
            ChessFigure figure = new ChessFigure(ChessFigure.Type.PAWN, "E2");

            Assert.AreEqual(false, figure.Move("C5"));
        }
コード例 #9
0
        public void KingShouldBeCorrectMove()
        {
            ChessFigure figure = new ChessFigure(ChessFigure.Type.KING, "E1");

            Assert.AreEqual(true, figure.Move("E2"));
        }
コード例 #10
0
        public void BishopShouldBeIncorrectMove()
        {
            ChessFigure figure = new ChessFigure(ChessFigure.Type.BISHOP, "C1");

            Assert.AreEqual(false, figure.Move("C3"));
        }
コード例 #11
0
        public void PawnShouldBeCorrectMove2()
        {
            ChessFigure figure = new ChessFigure(ChessFigure.Type.PAWN, "E4");

            Assert.AreEqual(true, figure.Move("E5"));
        }
コード例 #12
0
        public void KnightShouldBeIncorrectMove()
        {
            ChessFigure figure = new ChessFigure(ChessFigure.Type.KNIGHT, "B1");

            Assert.AreEqual(false, figure.Move("C5"));
        }
コード例 #13
0
        public void QueenShouldBeIncorrectMove()
        {
            ChessFigure figure = new ChessFigure(ChessFigure.Type.QUEEN, "D1");

            Assert.AreEqual(false, figure.Move("E3"));
        }
コード例 #14
0
        public void QueenShouldBeCorrectMoveDiagonal()
        {
            ChessFigure figure = new ChessFigure(ChessFigure.Type.QUEEN, "D1");

            Assert.AreEqual(true, figure.Move("H5"));
        }
コード例 #15
0
        public void PawnShouldBeCorrectMove1()
        {
            ChessFigure figure = ChessFigure.ConstructByType(FigureType.PAWN, "E2");

            Assert.AreEqual(true, figure.Move("E4"));
        }
コード例 #16
0
        public void KingShouldBeIncorrectMove()
        {
            ChessFigure figure = ChessFigure.ConstructByType(FigureType.KING, "E1");

            Assert.AreEqual(false, figure.Move("E8"));
        }
コード例 #17
0
ファイル: Form1.cs プロジェクト: TretiakovOA/Chess
        private void buttonMove_Click(object sender, EventArgs e)
        {
            ChessFigure figureToMove = GetFigure();

            if (figureToMove == null)
            {
                if (comboFrom.Text.Contains("Give In"))
                {
                    MessageBox.Show("You lose!");
                    GameBegins();
                    return;
                }
                if (comboFrom.Text.Contains("Draw"))
                {
                    DialogResult result = MessageBox.Show("Other player, do you want to draw?", "Draw proposal",
                                                          MessageBoxButtons.YesNo);
                    if (result == DialogResult.Yes)
                    {
                        MessageBox.Show("Draw!");
                        GameBegins();
                    }
                    return;
                }

                ChessKing        king  = Game.CurrentPlayer.Figures.OfType <ChessKing>().First();
                List <ChessRook> rooks = Game.CurrentPlayer.Figures.OfType <ChessRook>().ToList();
                ChessRook        rook  = null;
                if (comboFrom.Text == "Long Roque")
                {
                    rook = rooks.First(r => r.CurrentField.Column == 'A');
                }
                if (comboFrom.Text == "Short Roque")
                {
                    rook = rooks.First(r => r.CurrentField.Column == 'H');
                }
                if (rook == null)
                {
                    return;
                }
                rook.MakeRoque(Game.Board, king, Game.CurrentMoveNumber);
            }
            else
            {
                char[]      columnAndRow = comboTo.Text.ToCharArray();
                ChessField  field        = Game.Board.GetField(int.Parse(columnAndRow[1].ToString()), columnAndRow[0]);
                ChessPlayer enemy        = Game.CurrentPlayer.Color == ChessColor.WHITE ? Game.BlackPlayer : Game.WhitePlayer;
                figureToMove.Move(field, enemy, Game.Board, Game.CurrentMoveNumber, Game.CurrentPlayer.Figures);
            }

            bool check = Check();
            bool mate  = CheckMate();

            Game.ChangePlayer();
            DrawFigures();
            PrepareFigures();
            if (mate)
            {
                MessageBox.Show("MATE!");
                GameBegins();
            }
            else if (check)
            {
                MessageBox.Show("CHECK!");
            }
        }
コード例 #18
0
        public void RookShouldBeCorrectMove()
        {
            ChessFigure figure = new ChessFigure(ChessFigure.Type.ROOK, "E2");

            Assert.AreEqual(true, figure.Move("C2"));
        }