diff --git a/CoopSweeper/GameTypes/Field.cs b/CoopSweeper/GameTypes/Field.cs index ddb2929..3e9a384 100644 --- a/CoopSweeper/GameTypes/Field.cs +++ b/CoopSweeper/GameTypes/Field.cs @@ -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() { diff --git a/CoopSweeper/GameTypes/Game.cs b/CoopSweeper/GameTypes/Game.cs index 64e4d66..c6259c2 100644 --- a/CoopSweeper/GameTypes/Game.cs +++ b/CoopSweeper/GameTypes/Game.cs @@ -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 } } -} +} \ No newline at end of file diff --git a/CoopSweeper/GameTypes/IField.cs b/CoopSweeper/GameTypes/IField.cs index 51ea0c0..3318544 100644 --- a/CoopSweeper/GameTypes/IField.cs +++ b/CoopSweeper/GameTypes/IField.cs @@ -19,6 +19,8 @@ namespace CoopSweeper.GameTypes int SurroundingBombs { get; set; } + int CheckID { get; set; } + FieldState State { get; set; } char ToChar();