diff --git a/CoopSweeper/GameTypes/Field.cs b/CoopSweeper/GameTypes/Field.cs index ac69500..6f5afdd 100644 --- a/CoopSweeper/GameTypes/Field.cs +++ b/CoopSweeper/GameTypes/Field.cs @@ -16,6 +16,8 @@ namespace CoopSweeper.GameTypes public FieldState State { get; set; } + public int SurroundingBombs { get; set; } + public char ToChar() { throw new NotImplementedException(); diff --git a/CoopSweeper/GameTypes/Game.cs b/CoopSweeper/GameTypes/Game.cs index 1b29aec..64e4d66 100644 --- a/CoopSweeper/GameTypes/Game.cs +++ b/CoopSweeper/GameTypes/Game.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Drawing; using System.Text; namespace CoopSweeper.GameTypes @@ -30,6 +31,39 @@ namespace CoopSweeper.GameTypes Map[i, j] = field; } } + + UpdateSorroundingBombs(); + } + + private void UpdateSorroundingBombs() + { + for (int i = 0; i < Map.GetLength(0); i++) + { + for (int j = 0; j < Map.GetLength(1); j++) + { + var field = Map[i, j]; + + + } + } + } + + private List GetSorroundedFields(int x, int y) + { + var points = new List(); + points.Add(new Point(x - 1, y - 1)); + points.Add(new Point(x, y - 1)); + points.Add(new Point(x + 1, y - 1)); + + points.Add(new Point(x + 1, y)); + points.Add(new Point(x - 1, y)); + + points.Add(new Point(x - 1, y + 1)); + points.Add(new Point(x, y + 1)); + points.Add(new Point(x + 1, y + 1)); + + + return points; } public void GenerateGame(int x, int y) @@ -65,6 +99,7 @@ namespace CoopSweeper.GameTypes public void Reveal(int x, int y) { + CheckMap(); var field = Map[x, y]; if (field.State != FieldState.REVEALED) { @@ -77,24 +112,23 @@ namespace CoopSweeper.GameTypes GameFinished?.Invoke(true); } - public void SetQuestionMark(int x, int y) - { - Map[x, y].State = FieldState.QUESTIONMARK; - } - - public void SetFlag(int x, int y) - { - Map[x, y].State = FieldState.FLAG; - } - - public void ResetField(int x, int y) + public void ToggleMark(int x, int y) { + CheckMap(); var field = Map[x, y]; - if (field.State == FieldState.REVEALED) - throw new Exception("A Revealed Field can't be resetet!"); - - field.State = FieldState.FLAG; + switch (field.State) + { + case FieldState.NONE: + field.State = FieldState.FLAG; + return; + case FieldState.FLAG: + field.State = FieldState.QUESTIONMARK; + return; + case FieldState.QUESTIONMARK: + field.State = FieldState.NONE; + return; + } } } diff --git a/CoopSweeper/GameTypes/IField.cs b/CoopSweeper/GameTypes/IField.cs index ff1e1eb..51ea0c0 100644 --- a/CoopSweeper/GameTypes/IField.cs +++ b/CoopSweeper/GameTypes/IField.cs @@ -17,6 +17,8 @@ namespace CoopSweeper.GameTypes bool ContainsBomb { get; set; } + int SurroundingBombs { get; set; } + FieldState State { get; set; } char ToChar(); diff --git a/CoopSweeper/GameTypes/IGame.cs b/CoopSweeper/GameTypes/IGame.cs index 2383ace..da89285 100644 --- a/CoopSweeper/GameTypes/IGame.cs +++ b/CoopSweeper/GameTypes/IGame.cs @@ -10,10 +10,6 @@ namespace CoopSweeper.GameTypes void Reveal(int x, int y); - void SetQuestionMark(int x, int y); - - void SetFlag(int x, int y); - - void ResetField(int x, int y); + void ToggleMark(int x, int y); } }