implemented sorrounding bombs
This commit is contained in:
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
@@ -19,6 +19,8 @@ namespace CoopSweeper.GameTypes
|
||||
|
||||
int SurroundingBombs { get; set; }
|
||||
|
||||
int CheckID { get; set; }
|
||||
|
||||
FieldState State { get; set; }
|
||||
|
||||
char ToChar();
|
||||
|
||||
Reference in New Issue
Block a user