diff --git a/Field.cs b/Field.cs index 13abc93..034ef2c 100644 --- a/Field.cs +++ b/Field.cs @@ -95,8 +95,27 @@ if (y < 0 || y >= height || x < 0 || x >= width) throw new Exception("Coordinates out of the field!"); cells[y * width + x].open(); + if (cells[y * width + x].isEmpty()) + this.recur_open(y, x, new List()); return cells[y * width + x].isMine; } + private void recur_open(int y, int x, List opened) + { + if (!cells[y * width + x].isMine) + cells[y * width + x].open(); + if (cells[y * width + x].isEmpty() && !opened.Contains(cells[y * width + x])) + { + opened.Add(cells[y * width + x]); + if (x < width - 1) + this.recur_open(y, x + 1, opened); + if (x > 0) + this.recur_open(y, x - 1, opened); + if (y < height - 1) + this.recur_open(y + 1, x, opened); + if (y > 0) + this.recur_open(y - 1, x, opened); + } + } public void openall() { for (int i = 0; i < size; i++)