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

View File

@@ -8,6 +8,7 @@ namespace CoopSweeper.GameTypes
class Game
{
private readonly Random _random = new Random();
private static int _checkID = 0;
public IField[,] Map { get; protected set; }
@@ -41,9 +42,14 @@ namespace CoopSweeper.GameTypes
{
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 + 1, y + 1));
points.RemoveAll(point =>
point.X < 0
|| point.Y < 0
|| point.X >= Map.GetLength(0)
|| point.Y >= Map.GetLength(1));
return points;
}
@@ -76,11 +87,11 @@ namespace CoopSweeper.GameTypes
if (Map == null)
throw new ArgumentNullException("The Map isn't created yet!");
}
public delegate void GameFinishedHandler(bool isGameWon);
public event GameFinishedHandler GameFinished;
private bool CheckGameFinished()
{
for (int i = 0; i < Map.GetLength(0); i++)
@@ -97,10 +108,15 @@ namespace CoopSweeper.GameTypes
return true;
}
public void Reveal(int x, int y)
{
CheckMap();
var field = Map[x, y];
//if (field.CheckID < _checkID)
// return;
if (field.State != FieldState.REVEALED)
{
field.State = FieldState.REVEALED;
@@ -110,6 +126,8 @@ namespace CoopSweeper.GameTypes
if (CheckGameFinished())
GameFinished?.Invoke(true);
//_checkID
}
public void ToggleMark(int x, int y)
@@ -132,4 +150,4 @@ namespace CoopSweeper.GameTypes
}
}
}
}

View File

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