auto reveal

This commit is contained in:
Tim Wundenberg
2018-05-26 09:13:05 +02:00
parent e70f2031b9
commit 1886538e1e

View File

@@ -108,7 +108,7 @@ namespace CoopSweeper.GameTypes
return true; return true;
} }
private void InternalReveal(int x, int y) private void InternalReveal(int x, int y, bool revealSurroundings)
{ {
var field = Map[x, y]; var field = Map[x, y];
if (field.CheckID == _checkID) if (field.CheckID == _checkID)
@@ -118,6 +118,9 @@ namespace CoopSweeper.GameTypes
if (field.State != FieldState.REVEALED) if (field.State != FieldState.REVEALED)
{ {
if (field.State == FieldState.FLAG)
return;
field.State = FieldState.REVEALED; field.State = FieldState.REVEALED;
if (field.ContainsBomb) if (field.ContainsBomb)
FinishGame(false); FinishGame(false);
@@ -125,14 +128,40 @@ namespace CoopSweeper.GameTypes
if (field.SurroundingBombs == 0) if (field.SurroundingBombs == 0)
foreach (var surField in GetSorroundedFields(x, y)) 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()) if (CheckGameFinished())
FinishGame(true); 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() private void RevealBombs()
{ {
@@ -156,7 +185,7 @@ namespace CoopSweeper.GameTypes
{ {
CheckMap(); CheckMap();
_checkID++; _checkID++;
InternalReveal(x, y); InternalReveal(x, y, true);
} }
public void ToggleMark(int x, int y) public void ToggleMark(int x, int y)