private void MoveFigureOnTheBoard(Figure currentFigure, int nextFigureRow, int nextFigureColumn) { int figureCurrentRow = currentFigure.Row; int figureCurrentColumn = currentFigure.Column; GameBoard[figureCurrentRow, figureCurrentColumn] = GetBoardCellColorSymbol(figureCurrentRow, figureCurrentColumn); GameBoard[nextFigureRow, nextFigureColumn] = currentFigure.DisplaySymbol; currentFigure.Row = nextFigureRow; currentFigure.Column = nextFigureColumn; }
private static bool IsFigureMovingInCorrectTurn(Figure currentFigure, bool isKingTurn) { bool isFigureMovingInCorrectTurn = true; //Check if now is king turn and figure is a pawn bool isPawnTurn = !isKingTurn; var currentFigureType = currentFigure.Type; if (isKingTurn && currentFigureType == FigureType.Pawn) { //It is king turn and figure is a pawn isFigureMovingInCorrectTurn = false; } else if (isPawnTurn && currentFigureType == FigureType.King) { //It is a pawns turn and figure is a king isFigureMovingInCorrectTurn = false; } return isFigureMovingInCorrectTurn; }
private Figure AddFigureToGame(FigureType figureType, char figureSymbol, int row, int column) { if (this.Figures.Where(f => f.DisplaySymbol == figureSymbol).Count()>0) { throw new FigureExistsException(string.Format("Figure {0} already exists!", figureSymbol)); } var figure = new Figure(figureType, figureSymbol, row, column); Figures.Add(figure); return figure; }
public bool TryFigureMove(Figure currentFigure, int rowDirection, int columnDirection, bool isKingTurn) { if (currentFigure == null) { throw new ArgumentNullException("currentFigure must not be null!"); } bool isFigureMovingInCorrectTurn = IsFigureMovingInCorrectTurn(currentFigure, isKingTurn); if (!isFigureMovingInCorrectTurn) { return false; } int nextFigureRow = currentFigure.Row + rowDirection; int nextFigureColumn = currentFigure.Column + columnDirection; bool isFigureMoveValid = IsCellValidForMoveTo(nextFigureRow, nextFigureColumn); if (!isFigureMoveValid) { return false; } MoveFigureOnTheBoard(currentFigure, nextFigureRow, nextFigureColumn); if (isKingTurn) { KingMovesCount++; } else { PawnsMovesCount++; } return isFigureMoveValid; }