Я программирую Сапер на Java для школьного проекта.У меня есть кусок кода, который работает, но просто очень медленно.Функция должна открывать ячейки, которые находятся рядом с пустой ячейкой (функция обычного сапера открывать рядом с ячейками).Проблема в том, что эта функция должна открыться для работы.Я надеюсь, что кто-то может мне помочь.
void floodFill() {
revealed = true; // Function is started and cell is revealed
// This block has to play through for every empty field
if (nr == 0) { //Checks if empty cell
if (revealed) { //Checks if already opened, if not, it will just draw it
for (int xoff = -1; xoff <= 1; xoff++) { //Checks surroundings
int celli = i + xoff;
if (celli < 0 || celli >= row)
continue;
for (int yoff = -1; yoff <= 1; yoff++) { //Checks surroundings
int cellj = j + yoff;
if (cellj < 0 || cellj >= col)
continue;
if (!grid[celli][cellj].revealed) {
grid[celli][cellj].revealed = true;
//Here it should play the block through with the new values
//Should be like "grid[celli][cellj].floodFill();",
//but should not open the function again
}
}
}
}
}
draw(); //Draws everything in a frame
}
Буду очень признателен за вашу помощь, заранее спасибо.