/// <summary> /// Disarms a cell and adds a mine to a random empty cell. /// Used if the first open cell by the user is a cell with mine. /// </summary> /// <param name="cellToDisarm">The cell to disarm.</param> private void DisarmFirstCell(ICell cellToDisarm) { // Store every cell without mine var emptyCells = new List <ICell>(); for (int i = 0; i < this.Cells.Count; i++) { if (!this.Cells[i].IsMined) { emptyCells.Add(this.Cells[i]); } } if (emptyCells.Count == 0) { throw new InvalidOperationException("Cannot disarm a cell because all other cells have mines!"); } // Add mine to a random empty cell int j = this.RandomGenerator.Next(emptyCells.Count); emptyCells[j].AddMine(); // Disarm the first cell and recalculate the neighbor mines count cellToDisarm.Disarm(); this.allNeighborMines = this.CalculateNeighborMines(); }