public void RecursiveOpen(int x, int y, Minefield mine) { if (mine.isOpened()) { return; } else { if (mine.bombInProximity != 0 || mine.CheckBomb()) { mine.OpenCover(); return; } else { mine.OpenCover(); if (y + 1 < fieldHeight) { RecursiveOpen(x, y + 1, field[x, y + 1].GetComponent <Minefield>()); } if (x + 1 < fieldWidth) { RecursiveOpen(x + 1, y, field[x + 1, y].GetComponent <Minefield>()); } if (y - 1 >= 0) { RecursiveOpen(x, y - 1, field[x, y - 1].GetComponent <Minefield>()); } if (x - 1 >= 0) { RecursiveOpen(x - 1, y, field[x - 1, y].GetComponent <Minefield>()); } } } }
public void BFSOpen(Minefield mine) { int x, y; Queue <Minefield> openQueue = new Queue <Minefield>(); Minefield currMine; openQueue.Enqueue(mine); if (mine.CheckBomb()) { mine.OpenCover(); } while (openQueue.Count > 0) { currMine = openQueue.Dequeue(); if (currMine.isOpened() || currMine.CheckBomb()) { continue; } x = currMine.Coords[0]; y = currMine.Coords[1]; if (currMine.bombInProximity != 0) { currMine.OpenCover(); continue; } currMine.OpenCover(); if (x < fieldWidth && y + 1 < fieldHeight) { openQueue.Enqueue(field[x, y + 1].GetComponent <Minefield>()); } if (x + 1 < fieldWidth && y < fieldHeight) { openQueue.Enqueue(field[x + 1, y].GetComponent <Minefield>()); } if (x >= 0 && y - 1 >= 0) { openQueue.Enqueue(field[x, y - 1].GetComponent <Minefield>()); } if (x - 1 >= 0 && y >= 0) { openQueue.Enqueue(field[x - 1, y].GetComponent <Minefield>()); } } }