diff --git a/CoopSweeper/GameTypes/Game.cs b/CoopSweeper/GameTypes/Game.cs index d971a0a..5c7bbfe 100644 --- a/CoopSweeper/GameTypes/Game.cs +++ b/CoopSweeper/GameTypes/Game.cs @@ -43,7 +43,7 @@ namespace CoopSweeper.GameTypes for (int j = 0; j < Map.GetLength(1); j++) { int bombCounter = 0; - foreach (var point in GetSorroundedFields(i, j)) + foreach (var point in GetSurroundedFields(i, j)) { if (Map[point.X, point.Y].ContainsBomb) bombCounter++; @@ -54,7 +54,7 @@ namespace CoopSweeper.GameTypes } } - private List GetSorroundedFields(int x, int y) + private List GetSurroundedFields(int x, int y) { var points = new List(); points.Add(new Point(x - 1, y - 1)); @@ -123,10 +123,13 @@ namespace CoopSweeper.GameTypes field.State = FieldState.REVEALED; if (field.ContainsBomb) + { FinishGame(false); + return; + } if (field.SurroundingBombs == 0) - foreach (var surField in GetSorroundedFields(x, y)) + foreach (var surField in GetSurroundedFields(x, y)) { InternalReveal(surField.X, surField.Y, false); } @@ -138,7 +141,10 @@ namespace CoopSweeper.GameTypes } if (CheckGameFinished()) + { FinishGame(true); + return; + } } private void RevealSurroindings(int x, int y) @@ -146,14 +152,14 @@ namespace CoopSweeper.GameTypes int bombs = Map[x, y].SurroundingBombs; int bombsFlagged = 0; - foreach (var point in GetSorroundedFields(x, y)) + foreach (var point in GetSurroundedFields(x, y)) { - if (Map[point.X, point.Y].ContainsBomb && Map[point.X, point.Y].State == FieldState.FLAG) + if (Map[point.X, point.Y].State == FieldState.FLAG) bombsFlagged++; } if (bombsFlagged == bombs) - foreach (var point in GetSorroundedFields(x, y)) + foreach (var point in GetSurroundedFields(x, y)) { if (Map[point.X, point.Y].State != FieldState.FLAG) InternalReveal(point.X, point.Y, false); diff --git a/CoopSweeper/Program.cs b/CoopSweeper/Program.cs index 981f771..ce9faf2 100644 --- a/CoopSweeper/Program.cs +++ b/CoopSweeper/Program.cs @@ -33,7 +33,7 @@ namespace CoopSweeper StartNewGame(game, cursorPosX, cursorPosY); }; ConsoleKey key = (ConsoleKey)(-1); - do + while ((key = Console.ReadKey().Key) != ConsoleKey.Escape) { var oldCursorPosX = cursorPosX; var oldCursorPosY = cursorPosY; @@ -70,7 +70,7 @@ namespace CoopSweeper } Console.SetCursorPosition(0, 0); Console.CursorVisible = false; - } while ((key = Console.ReadKey().Key) != ConsoleKey.Escape); + } } private static void DrawChar(IField f, bool isCursor)