IEnumerator replaceCellWithRevealed(MineSweeperCell cell) { List <MineSweeperCell> cellsToReveal = new List <MineSweeperCell>(); cellsToReveal.Add(cell); int countBeforeRender = revealBatchSize; while (cellsToReveal.Count > 0) { MineSweeperCell currentCell = cellsToReveal[0]; cellsToReveal.RemoveAt(0); if (currentCell.getState() != CellState.initial) { continue; } currentCell.setState(CellState.revealed); int currX = currentCell.getX(); int currY = currentCell.getY(); int currZ = currentCell.getZ(); int nbNeighbourMines = countNeighbourMines(currX, currY, currZ); if (nbNeighbourMines > 0) { showNeighboursCount(currentCell, nbNeighbourMines); } else { foreach (GridCoordinate coords in neighbourCoordinates(currX, currY, currZ)) { MineSweeperCell neighbourCell = cells[getCellIndex(coords.x, coords.y, coords.z)]; if (coords.x == currX && coords.y == currY && coords.z == currZ || neighbourCell.getState() != CellState.initial ) { continue; } cellsToReveal.Add(neighbourCell); } } countBeforeRender--; if (countBeforeRender == 0) { countBeforeRender = revealBatchSize; yield return(null); } currentCell.gameObject.SetActive(false); } setWin(); yield return(null); }
public void revealCell(MineSweeperCell cell) { int x = cell.getX(); int y = cell.getY(); int z = cell.getZ(); if (!acted) { acted = true; setMines(x, y, z); context.startTimer(); } if (cell.hasMine()) { deactivate(); showMines(cell); context.setLost(); } else { StartCoroutine("replaceCellWithRevealed", cells[getCellIndex(x, y, z)]); } }