/// <summary> /// Creates a new empty grid array. /// </summary> /// <param name="width">The width of the grid.</param> /// <param name="height">The height of the grid.</param> /// <returns></returns> private static BoardSlotValue[,] CreateNewEmptyGridArray(int columns, int rows) { var grid = new BoardSlotValue[rows, columns]; var gridSize = grid.ToBoardSize(); for (var rowIndex = 0; rowIndex < gridSize.Height - 1; rowIndex++) { for (var columnIndex = 0; columnIndex < gridSize.Width - 1; columnIndex++) { grid[rowIndex, columnIndex] = BoardSlotValue.Empty; } } return(grid); }
/// <inheritdocs/> public IReadOnlyBoardGrid DropValueIntoColumn(BoardSlotValue boardSlotValue, int columnIndex) { if (IsBoardFull()) { throw new BoardIsFullException(); } if (IsColumnFull(columnIndex)) { throw new ColumnIsFullException(columnIndex); } var firstEmptySlotPosition = GetFirstEmptySlotPositionForColumn(columnIndex); SetValueOnPosition(boardSlotValue, firstEmptySlotPosition); return(this); }
private ConsoleColor GetColorBasedOnSlotValue(BoardSlotValue boardSlotValue) => boardSlotValue == BoardSlotValue.P1 ? ConsoleColor.Red : ConsoleColor.Yellow ;
private void ChangeToColorBasedOnSlotValue(BoardSlotValue boardSlotValue) => ChangeToColor(GetColorBasedOnSlotValue(boardSlotValue)) ;
/// <summary> /// Creates a new <see cref="Player"/>. /// </summary> internal Player(string name, BoardSlotValue type) { Name = name; Type = type; }
/// <summary> /// Creates a <see cref="WinStateCalculatorResult"/> based on the defined <see cref="WinMethod"/> with the given <paramref name="winner"/>. /// </summary> /// <param name="winner">The one that has won the game.</param> protected WinStateCalculatorResult WinnerResult(BoardSlotValue winner) => new WinStateCalculatorResult(WinMethod, winner);
/// <summary> /// Sets the specified <paramref name="boardSlotValue"/> on the given <paramref name="boardPosition"/>. /// </summary> /// <param name="boardSlotValue">The value to set.</param> /// <param name="boardPosition">The position where to set it.</param> private void SetValueOnPosition(BoardSlotValue boardSlotValue, BoardPosition boardPosition) => _grid[boardPosition.Row - 1, boardPosition.Column - 1] = boardSlotValue;
/// <summary> /// Creates a new <see cref="BoardSlot"/> based on the given <paramref name="value"/> and <paramref name="position"/>. /// </summary> /// <param name="value">The value the slot holds.</param> /// <param name="position">The position of the slot.</param> internal BoardSlot(BoardSlotValue value, BoardPosition position) { Value = value; Position = position; }
/// <summary> /// Creates a new <see cref="BoardSlot"/> based on the given <paramref name="value"/> and the position by the 1-based <paramref name="rowIndex"/> and the 1-based <paramref name="columnIndex"/>. /// </summary> /// <param name="value">The value the slot holds.</param> /// <param name="rowIndex">The 1-based index of the row the slot is positioned at.</param> /// <param name="columnIndex">The 1-based index of the column the slot is positioned at.</param> internal BoardSlot(BoardSlotValue value, int rowIndex, int columnIndex) : this(value, new BoardPosition(rowIndex, columnIndex)) { }