public Chess(ChessFigure.Type type, string currentCoord) { if (type == ChessFigure.Type.PAWN) { ChessFigure = new ChessPawn(type, currentCoord); } if (type == ChessFigure.Type.BISHOP) { ChessFigure = new ChessBishop(type, currentCoord); } if (type == ChessFigure.Type.KING) { ChessFigure = new ChessKing(type, currentCoord); } if (type == ChessFigure.Type.KNIGHT) { ChessFigure = new ChessKnight(type, currentCoord); } if (type == ChessFigure.Type.QUEEN) { ChessFigure = new ChessQueen(type, currentCoord); } if (type == ChessFigure.Type.ROOK) { ChessFigure = new ChessRook(type, currentCoord); } }
private void SetFigureStartPosition(ChessFigure figure, bool color) { if (figure is Elephant) { Elephant elephantc1 = new Elephant(new Coordinates('c', 1), true); Elephant elephantf1 = new Elephant(new Coordinates('f', 1), true); Elephant elephantc8 = new Elephant(new Coordinates('c', 8), false); Elephant elephantf8 = new Elephant(new Coordinates('f', 1), false); } else if (figure is Castle) { Castle castlea1 = new Castle(new Coordinates('a', 1), true); Castle castleh1 = new Castle(new Coordinates('h', 1), true); Castle castlea8 = new Castle(new Coordinates('a', 8), false); Castle castleh8 = new Castle(new Coordinates('h', 8), false); } else if (figure is Horse) { Horse horseb1 = new Horse(new Coordinates('b', 1), true); Horse horseg1 = new Horse(new Coordinates('g', 1), true); Horse horseb8 = new Horse(new Coordinates('b', 8), false); Horse horseg8 = new Horse(new Coordinates('g', 8), false); } else if (figure is King) { King kinge1 = new King(new Coordinates('e', 1), true); King kinge8 = new King(new Coordinates('e', 8), false); } else if (figure is Queen) { Queen queend1 = new Queen(new Coordinates('d', 1), true); Queen queend8 = new Queen(new Coordinates('d', 8), false); } else if (figure is Pawn) { Pawn pawna2 = new Pawn(new Coordinates('a', 2), true); Pawn pawnb2 = new Pawn(new Coordinates('b', 2), true); Pawn pawnc2 = new Pawn(new Coordinates('c', 2), true); Pawn pawnd2 = new Pawn(new Coordinates('d', 2), true); Pawn pawne2 = new Pawn(new Coordinates('e', 2), true); Pawn pawnf2 = new Pawn(new Coordinates('f', 2), true); Pawn pawng2 = new Pawn(new Coordinates('g', 2), true); Pawn pawnh2 = new Pawn(new Coordinates('h', 2), true); Pawn pawna7 = new Pawn(new Coordinates('a', 7), false); Pawn pawnb7 = new Pawn(new Coordinates('b', 7), false); Pawn pawnc7 = new Pawn(new Coordinates('c', 7), false); Pawn pawnd7 = new Pawn(new Coordinates('d', 7), false); Pawn pawne7 = new Pawn(new Coordinates('e', 7), false); Pawn pawnf7 = new Pawn(new Coordinates('f', 7), false); Pawn pawng7 = new Pawn(new Coordinates('g', 7), false); Pawn pawnh7 = new Pawn(new Coordinates('h', 7), false); } }
private void PrepareMoves() { List <string> fieldStrings = new List <string>(); ChessFigure figureToMove = GetFigure(); if (figureToMove == null) { return; } foreach (ChessField moveTo in figureToMove.FieldsToMove) { fieldStrings.Add(moveTo.Column.ToString() + moveTo.Row); } comboTo.DataSource = fieldStrings; comboTo.SelectedIndex = 0; }
private ChessFigure GetFigure() { string selectedText = comboFrom.Text; if (selectedText.Contains("Roque") || selectedText.Contains("Decision")) { return(null); } int row = int.Parse(selectedText.Substring(selectedText.Length - 1)); char column = selectedText.ToCharArray()[selectedText.Length - 2]; ChessField field = Game.Board.GetField(row, column); ChessFigure figureToMove = null; foreach (var figure in Game.CurrentPlayer.Figures) { if (figure.CurrentField == field) { figureToMove = figure; break; } } return(figureToMove); }
public void QueenShouldBeCorrectMoveDiagonal() { ChessFigure figure = ChessFigure.ConstructByType(FigureType.QUEEN, "D1"); Assert.AreEqual(true, figure.Move("H5")); }
public void BishopShouldBeIncorrectMove() { ChessFigure figure = new ChessFigure("C1", new MoveBishop()); Assert.AreEqual(false, figure.MoveTo("E3")); }
public void KingShouldBeIncorrectMove() { ChessFigure figure = ChessFigure.ConstructByType(FigureType.KING, "E1"); Assert.AreEqual(false, figure.Move("E8")); }
public void PawnShouldBeCorrectMove1() { ChessFigure figure = ChessFigure.ConstructByType(FigureType.PAWN, "E2"); Assert.AreEqual(true, figure.Move("E4")); }
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!"); } }
public void FigureMoveToInvalidCoord(string coord) { ChessFigure figure = ChessFigure.ConstructByType(FigureType.ROOK, "E2"); Assert.Throws <ArgumentOutOfRangeException>(() => figure.Move(coord)); }
public void KnightShouldBeIncorrectMove() { ChessFigure figure = ChessFigure.ConstructByType(FigureType.KNIGHT, "B1"); Assert.AreEqual(false, figure.Move("C5")); }
public void QueenShouldBeIncorrectMove() { ChessFigure figure = new ChessFigure(ChessFigure.Type.QUEEN, "D1"); Assert.AreEqual(false, figure.Move("E3")); }
public void KnightShouldBeIncorrectMove() { ChessFigure figure = new ChessFigure(ChessFigure.Type.KNIGHT, "B1"); Assert.AreEqual(false, figure.Move("C5")); }
public void KingShouldBeIncorrectMove() { ChessFigure figure = new ChessFigure(ChessFigure.Type.KING, "E1"); Assert.AreEqual(false, figure.Move("E8")); }
public void QueenShouldBeCorrectMoveDiagonal() { ChessFigure figure = new ChessFigure(ChessFigure.Type.QUEEN, "D1"); Assert.AreEqual(true, figure.Move("H5")); }
public void KingShouldBeCorrectMove() { ChessFigure figure = new ChessFigure("E1", new MoveKing()); Assert.AreEqual(true, figure.MoveTo("E2")); }
public void PawnShouldBeIncorrectMove() { ChessFigure figure = new ChessFigure("E2", new MovePawn()); Assert.AreEqual(false, figure.MoveTo("C5")); }
public void PawnShouldBeCorrectMove2() { ChessFigure figure = new ChessFigure("E4", new MovePawn()); Assert.AreEqual(true, figure.MoveTo("E5")); }
public void QueenShouldBeIncorrectMove() { ChessFigure figure = ChessFigure.ConstructByType(FigureType.QUEEN, "D1"); Assert.AreEqual(false, figure.Move("E3")); }
public void BishopShouldBeIncorrectMove() { ChessFigure figure = new ChessFigure(ChessFigure.Type.BISHOP, "C1"); Assert.AreEqual(false, figure.Move("C3")); }
public void FigureWithInvalidCoord(string coord) { Assert.Throws <ArgumentOutOfRangeException>(() => ChessFigure.ConstructByType(FigureType.ROOK, coord)); }
public void PawnShouldBeCorrectMove2() { ChessFigure figure = new ChessFigure(ChessFigure.Type.PAWN, "E4"); Assert.AreEqual(true, figure.Move("E5")); }
public void RookShouldBeIncorrectMove() { ChessFigure figure = ChessFigure.ConstructByType(FigureType.ROOK, "E2"); Assert.AreEqual(false, figure.Move("C5")); }
public void RookShouldBeCorrectMove() { ChessFigure figure = new ChessFigure("E2", new MoveRook()); Assert.AreEqual(true, figure.MoveTo("C2")); }
public void BishopShouldBeIncorrectMove() { ChessFigure figure = ChessFigure.ConstructByType(FigureType.BISHOP, "C1"); Assert.AreEqual(false, figure.Move("C3")); }
public void KingShouldBeCorrectMove() { ChessFigure figure = new ChessFigure(ChessFigure.Type.KING, "E1"); Assert.AreEqual(true, figure.Move("E2")); }
public void QueenShouldBeIncorrectMove() { ChessFigure figure = new ChessFigure("D1", new MoveQueen()); Assert.AreEqual(false, figure.MoveTo("E3")); }
public void KnightShouldBeCorrectMove() { ChessFigure figure = new ChessFigure("B1", new MoveKnight()); Assert.AreEqual(true, figure.MoveTo("C3")); }
public void PawnShouldBeIncorrectMove() { ChessFigure figure = new ChessFigure(ChessFigure.Type.PAWN, "E2"); Assert.AreEqual(false, figure.Move("C5")); }
public void KnightShouldBeIncorrectMove() { ChessFigure figure = new ChessFigure("B1", new MoveKnight()); Assert.AreEqual(false, figure.MoveTo("C5")); }