private void PasteBombs() { for (var bombsPasted = 0; bombsPasted < NumMines;) { var randX = random.Next(Width); var randY = random.Next(Height); if (Cells[randX, randY].CellState == CellState.Closed && Cells[randX, randY].FirstPick == false && Cells[randX, randY].CellType != CellType.Mine) { Cells[randX, randY].CellType = CellType.Mine; //Cells[randX, randY].Text = "M"; bombsPasted++; } } foreach (var item in Cells) { foreach (var itemCell in GetNeighborCell.GetCells(Cells, item.XLoc, item.YLoc, Width, Height)) { if (itemCell.CellType == CellType.Mine && item.CellType != CellType.Mine) { item.NumMines++; } } } }
private void FirstClickAction(Cell input) { _firstClick = false; var firstClickNeighbors = GetNeighborCell.GetCells(Cells, input.XLoc, input.YLoc, Width, Height); for (var i = 0; i < firstClickNeighbors.Count; i++) { firstClickNeighbors[i].FirstPick = true; } PasteBombs(); }
private void FloodFill(int x, int y) { var neighborCells = GetNeighborCell.GetCells(Cells, x, y, Width, Height); foreach (var neighbor in neighborCells) { if (neighbor.CellState == CellState.Closed && neighbor.CellType == CellType.Regular) { neighbor.OnClick(); if (neighbor.NumMines == 0) { FloodFill(neighbor.XLoc, neighbor.YLoc); } } } }