Fix automatic reveal on restart

This commit is contained in:
Marvin Rohrbach
2018-12-15 16:39:12 +01:00
parent 07eeec1032
commit 624f6d1ea6
2 changed files with 14 additions and 8 deletions

View File

@@ -43,7 +43,7 @@ namespace CoopSweeper.GameTypes
for (int j = 0; j < Map.GetLength(1); j++) for (int j = 0; j < Map.GetLength(1); j++)
{ {
int bombCounter = 0; int bombCounter = 0;
foreach (var point in GetSorroundedFields(i, j)) foreach (var point in GetSurroundedFields(i, j))
{ {
if (Map[point.X, point.Y].ContainsBomb) if (Map[point.X, point.Y].ContainsBomb)
bombCounter++; bombCounter++;
@@ -54,7 +54,7 @@ namespace CoopSweeper.GameTypes
} }
} }
private List<Point> GetSorroundedFields(int x, int y) private List<Point> GetSurroundedFields(int x, int y)
{ {
var points = new List<Point>(); var points = new List<Point>();
points.Add(new Point(x - 1, y - 1)); points.Add(new Point(x - 1, y - 1));
@@ -123,10 +123,13 @@ namespace CoopSweeper.GameTypes
field.State = FieldState.REVEALED; field.State = FieldState.REVEALED;
if (field.ContainsBomb) if (field.ContainsBomb)
{
FinishGame(false); FinishGame(false);
return;
}
if (field.SurroundingBombs == 0) if (field.SurroundingBombs == 0)
foreach (var surField in GetSorroundedFields(x, y)) foreach (var surField in GetSurroundedFields(x, y))
{ {
InternalReveal(surField.X, surField.Y, false); InternalReveal(surField.X, surField.Y, false);
} }
@@ -138,7 +141,10 @@ namespace CoopSweeper.GameTypes
} }
if (CheckGameFinished()) if (CheckGameFinished())
{
FinishGame(true); FinishGame(true);
return;
}
} }
private void RevealSurroindings(int x, int y) private void RevealSurroindings(int x, int y)
@@ -146,14 +152,14 @@ namespace CoopSweeper.GameTypes
int bombs = Map[x, y].SurroundingBombs; int bombs = Map[x, y].SurroundingBombs;
int bombsFlagged = 0; 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++; bombsFlagged++;
} }
if (bombsFlagged == bombs) 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) if (Map[point.X, point.Y].State != FieldState.FLAG)
InternalReveal(point.X, point.Y, false); InternalReveal(point.X, point.Y, false);

View File

@@ -33,7 +33,7 @@ namespace CoopSweeper
StartNewGame(game, cursorPosX, cursorPosY); StartNewGame(game, cursorPosX, cursorPosY);
}; };
ConsoleKey key = (ConsoleKey)(-1); ConsoleKey key = (ConsoleKey)(-1);
do while ((key = Console.ReadKey().Key) != ConsoleKey.Escape)
{ {
var oldCursorPosX = cursorPosX; var oldCursorPosX = cursorPosX;
var oldCursorPosY = cursorPosY; var oldCursorPosY = cursorPosY;
@@ -70,7 +70,7 @@ namespace CoopSweeper
} }
Console.SetCursorPosition(0, 0); Console.SetCursorPosition(0, 0);
Console.CursorVisible = false; Console.CursorVisible = false;
} while ((key = Console.ReadKey().Key) != ConsoleKey.Escape); }
} }
private static void DrawChar(IField f, bool isCursor) private static void DrawChar(IField f, bool isCursor)