public ChessPlayer(Color color, ChessBoard board) { Color = color; Figures = new ChessFigure[16]; Figures[0] = new ChessKing(color, board); Figures[1] = new ChessQueen(color, board); Figures[2] = new ChessBishop(color, board, true); Figures[3] = new ChessBishop(color, board, false); Figures[4] = new ChessKnight(color, board, true); Figures[5] = new ChessKnight(color, board, false); Figures[6] = new ChessRook(color, board, true); Figures[7] = new ChessRook(color, board, false); Figures[8] = new ChessPawn(color, board, 'A'); Figures[9] = new ChessPawn(color, board, 'B'); Figures[10] = new ChessPawn(color, board, 'C'); Figures[11] = new ChessPawn(color, board, 'D'); Figures[12] = new ChessPawn(color, board, 'E'); Figures[13] = new ChessPawn(color, board, 'F'); Figures[14] = new ChessPawn(color, board, 'G'); Figures[15] = new ChessPawn(color, board, 'H'); }
public override void Move(ChessField field, ChessPlayer enemy, ChessBoard board, int moveNumber, ChessFigure[] otherFigures) { if (PreviousMoves.Count == 0) { if ((Color == Color.WHITE && field.Row == 4) || (Color == Color.BLACK && field.Row == 5)) { EnPassant = true; EnPassantMove = moveNumber; } } else { EnPassant = false; } base.Move(field, enemy, board, moveNumber, otherFigures); if ((Color == Color.WHITE && field.Row == 8) || (Color == Color.BLACK && field.Row == 1)) { int pawnIndex = 16; for (var i = 0; i < otherFigures.Length; i++) { var figure = otherFigures[i]; if (this == figure) { pawnIndex = i; } } ChessFigure newFigure; DialogResult result = MessageBox.Show("Do you want to turn into Queen?", "Pawn To Queen", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { newFigure = new ChessQueen(Color, board); } else { result = MessageBox.Show("Do you want to turn into Rook?", "Pawn To Rook", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { newFigure = new ChessRook(Color, board, false); } else { result = MessageBox.Show("Do you want to turn into Knight?", "Pawn To Knight", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { newFigure = new ChessKnight(Color, board, false); } else { newFigure = new ChessBishop(Color, board, false); } } } newFigure.CurrentField = field; newFigure.PreviousMoves = PreviousMoves; newFigure.FindFieldsToMove(board); otherFigures[pawnIndex] = newFigure; } }