diff --git a/CoopSweeper/GameTypes/Game.cs b/CoopSweeper/GameTypes/Game.cs index 70ee161..d971a0a 100644 --- a/CoopSweeper/GameTypes/Game.cs +++ b/CoopSweeper/GameTypes/Game.cs @@ -108,7 +108,7 @@ namespace CoopSweeper.GameTypes return true; } - private void InternalReveal(int x, int y) + private void InternalReveal(int x, int y, bool revealSurroundings) { var field = Map[x, y]; if (field.CheckID == _checkID) @@ -118,6 +118,9 @@ namespace CoopSweeper.GameTypes if (field.State != FieldState.REVEALED) { + if (field.State == FieldState.FLAG) + return; + field.State = FieldState.REVEALED; if (field.ContainsBomb) FinishGame(false); @@ -125,14 +128,40 @@ namespace CoopSweeper.GameTypes if (field.SurroundingBombs == 0) foreach (var surField in GetSorroundedFields(x, y)) { - InternalReveal(surField.X, surField.Y); + InternalReveal(surField.X, surField.Y, false); } } + else + { + if (revealSurroundings) + RevealSurroindings(x, y); + } if (CheckGameFinished()) FinishGame(true); } + private void RevealSurroindings(int x, int y) + { + int bombs = Map[x, y].SurroundingBombs; + int bombsFlagged = 0; + + foreach (var point in GetSorroundedFields(x, y)) + { + if (Map[point.X, point.Y].ContainsBomb && Map[point.X, point.Y].State == FieldState.FLAG) + bombsFlagged++; + } + + if (bombsFlagged == bombs) + foreach (var point in GetSorroundedFields(x, y)) + { + if (Map[point.X, point.Y].State != FieldState.FLAG) + InternalReveal(point.X, point.Y, false); + } + + + } + private void RevealBombs() { @@ -156,7 +185,7 @@ namespace CoopSweeper.GameTypes { CheckMap(); _checkID++; - InternalReveal(x, y); + InternalReveal(x, y, true); } public void ToggleMark(int x, int y)