我正在为一个学校项目用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
}将会非常感谢你的帮助,提前谢谢。
发布于 2019-05-12 04:02:56
我猜您可以在每次显示一个空的磁贴时调用相同的方法,并递归地创建您的方法。你应该不会有运行时的问题,因为(如果我错了,请纠正我)你的T(n)将小于O(3^n),并且tiles的数量(可能)不会太多。
https://stackoverflow.com/questions/56093599
复制相似问题