public void TestKing_Position() { for (int i = 0; i < 100; i++) { Random random = new Random(); int row = random.Next(0, 7); int col = random.Next(0, 7); Position position = new Position(row, col); King king = new King(position); Assert.AreEqual<Position>(king.Position, position, "King`s position is not working correctly"); } }
public Figure(Position position, char symbol) { this.Position = position; //if (((int)symbol >= (int)'a') && ((int)'z' <= (int)symbol))) || // ((int)symbol >= (int)'A' && (int)'Z' <= (int)symbol)) if ((symbol >= 'A' && symbol <= 'Z') || (symbol >= 'a' && symbol <= 'z')) { this.symbolRepresentation = symbol; } else { throw new ArgumentOutOfRangeException("Not valid figure symbol"); } }
private bool IsValidGameBoardCell(Position position) { bool valid = this.gameBoard.IsInGameField(position) && this.gameBoard[position.Row, position.Column] == ' '; return valid; }
/// <summary> /// Gets the displacement for figure movement /// </summary> private Position GetDisplacement(Direction direction) { Position displacement = null; switch (direction) { case Direction.DL: displacement = new Position(1, -2); break; case Direction.DR: displacement = new Position(1, 2); break; case Direction.UL: displacement = new Position(-1, -2); break; case Direction.UR: displacement = new Position(-1, 2); break; default: throw new ArgumentException("Invalid direction for displacement!"); } return displacement; }
public void DrawGameBoard() { Console.WriteLine(); for (int row = 0; row < gameBoard.GetLength(0); row++) { for (int col = 0; col < gameBoard.GetLength(1); col++) { Position positionCell = new Position(row, col); bool isCellIn = IsInGameField(positionCell); if (isCellIn) { if (row % 2 == 0) { if (col % 4 == 0) { Console.BackgroundColor = ConsoleColor.Green; Console.ForegroundColor = ConsoleColor.Black; Console.Write(gameBoard[row, col]); Console.ResetColor(); } else if (col % 2 == 0) { Console.BackgroundColor = ConsoleColor.Blue; Console.ForegroundColor = ConsoleColor.Black; Console.Write(gameBoard[row, col]); Console.ResetColor(); } else //if (col % 2 != 0) { Console.Write(gameBoard[row, col]); } } else if (col % 4 == 0) { Console.BackgroundColor = ConsoleColor.Blue; Console.ForegroundColor = ConsoleColor.Black; Console.Write(gameBoard[row, col]); Console.ResetColor(); } else if (col % 2 == 0) { Console.BackgroundColor = ConsoleColor.Green; Console.ForegroundColor = ConsoleColor.Black; Console.Write(gameBoard[row, col]); Console.ResetColor(); } else //if (col % 2 != 0) { Console.Write(gameBoard[row, col]); } } else { Console.Write(gameBoard[row, col]); } } Console.WriteLine(); Console.ResetColor(); } Console.WriteLine(); }
public bool IsInGameField(Position position) { int positonRow = position.Row; bool isRowInBoard = (positonRow >= topLeft.Row) && (positonRow <= bottomLeft.Row); int positonCol = position.Column; bool isColInBoard = (positonCol >= topLeft.Column) && (positonCol <= topRight.Column); bool isValidPosition = isRowInBoard && isColInBoard; return isValidPosition; }
public King(Position position) : base(position, kingSymbol) { this.ExistingMoves = new bool[] { true, true, true, true }; }
public Pawn(Position position, char pawnSymbol) : base(position, pawnSymbol) { this.ExistingMoves = new bool[] { true, true }; }