implemented sorrounding bombs

This commit is contained in:
Tim Wundenberg
2018-05-25 11:21:18 +02:00
parent 7709f8dc7d
commit e0291a445d
3 changed files with 27 additions and 5 deletions

View File

@@ -10,6 +10,7 @@ namespace CoopSweeper.GameTypes
public Field() public Field()
{ {
State = FieldState.NONE; State = FieldState.NONE;
CheckID = 0;
} }
public bool ContainsBomb { get; set; } public bool ContainsBomb { get; set; }
@@ -17,6 +18,7 @@ namespace CoopSweeper.GameTypes
public FieldState State { get; set; } public FieldState State { get; set; }
public int SurroundingBombs { get; set; } public int SurroundingBombs { get; set; }
public int CheckID { get; set; }
public char ToChar() public char ToChar()
{ {

View File

@@ -8,6 +8,7 @@ namespace CoopSweeper.GameTypes
class Game class Game
{ {
private readonly Random _random = new Random(); private readonly Random _random = new Random();
private static int _checkID = 0;
public IField[,] Map { get; protected set; } public IField[,] Map { get; protected set; }
@@ -41,9 +42,14 @@ namespace CoopSweeper.GameTypes
{ {
for (int j = 0; j < Map.GetLength(1); j++) for (int j = 0; j < Map.GetLength(1); j++)
{ {
var field = Map[i, j]; int bombCounter = 0;
foreach (var point in GetSorroundedFields(i, j))
{
if (Map[point.X, point.Y].ContainsBomb)
bombCounter++;
}
Map[i, j].SurroundingBombs = bombCounter;
} }
} }
} }
@@ -62,6 +68,11 @@ namespace CoopSweeper.GameTypes
points.Add(new Point(x, y + 1)); points.Add(new Point(x, y + 1));
points.Add(new Point(x + 1, y + 1)); points.Add(new Point(x + 1, y + 1));
points.RemoveAll(point =>
point.X < 0
|| point.Y < 0
|| point.X >= Map.GetLength(0)
|| point.Y >= Map.GetLength(1));
return points; return points;
} }
@@ -97,10 +108,15 @@ namespace CoopSweeper.GameTypes
return true; return true;
} }
public void Reveal(int x, int y) public void Reveal(int x, int y)
{ {
CheckMap(); CheckMap();
var field = Map[x, y]; var field = Map[x, y];
//if (field.CheckID < _checkID)
// return;
if (field.State != FieldState.REVEALED) if (field.State != FieldState.REVEALED)
{ {
field.State = FieldState.REVEALED; field.State = FieldState.REVEALED;
@@ -110,6 +126,8 @@ namespace CoopSweeper.GameTypes
if (CheckGameFinished()) if (CheckGameFinished())
GameFinished?.Invoke(true); GameFinished?.Invoke(true);
//_checkID
} }
public void ToggleMark(int x, int y) public void ToggleMark(int x, int y)

View File

@@ -19,6 +19,8 @@ namespace CoopSweeper.GameTypes
int SurroundingBombs { get; set; } int SurroundingBombs { get; set; }
int CheckID { get; set; }
FieldState State { get; set; } FieldState State { get; set; }
char ToChar(); char ToChar();