コード例 #1
0
        /// <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);
        }
コード例 #2
0
        /// <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);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: KodeFoxx-Projects/Katas
 private ConsoleColor GetColorBasedOnSlotValue(BoardSlotValue boardSlotValue)
 => boardSlotValue == BoardSlotValue.P1
         ? ConsoleColor.Red
         : ConsoleColor.Yellow
 ;
コード例 #4
0
ファイル: Program.cs プロジェクト: KodeFoxx-Projects/Katas
 private void ChangeToColorBasedOnSlotValue(BoardSlotValue boardSlotValue)
 => ChangeToColor(GetColorBasedOnSlotValue(boardSlotValue))
 ;
コード例 #5
0
ファイル: Player.cs プロジェクト: KodeFoxx-Projects/Katas
 /// <summary>
 /// Creates a new <see cref="Player"/>.
 /// </summary>
 internal Player(string name, BoardSlotValue type)
 {
     Name = name;
     Type = type;
 }
コード例 #6
0
 /// <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);
コード例 #7
0
 /// <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;
コード例 #8
0
ファイル: BoardSlot.cs プロジェクト: KodeFoxx-Projects/Katas
 /// <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;
 }
コード例 #9
0
ファイル: BoardSlot.cs プロジェクト: KodeFoxx-Projects/Katas
 /// <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))
 {
 }