diff --git a/CoopSweeper/GameTypes/Field.cs b/CoopSweeper/GameTypes/Field.cs index 01aba62..36d1e56 100644 --- a/CoopSweeper/GameTypes/Field.cs +++ b/CoopSweeper/GameTypes/Field.cs @@ -7,8 +7,13 @@ namespace CoopSweeper.GameTypes class Field : IField { + public Field() + { + State = FieldState.NONE; + } + public bool ContainsBomb { get; set; } - public FieldState State { get; set;} + public FieldState State { get; set; } } } diff --git a/CoopSweeper/GameTypes/Game.cs b/CoopSweeper/GameTypes/Game.cs index fe63691..1116786 100644 --- a/CoopSweeper/GameTypes/Game.cs +++ b/CoopSweeper/GameTypes/Game.cs @@ -6,5 +6,36 @@ namespace CoopSweeper.GameTypes { class Game { + private readonly Random _random = new Random(); + + public IField[,] Map { get; protected set; } + + private bool IsBomb(int bombratePercent) + { + int r = _random.Next(0, 100); + return r < bombratePercent; + } + + public void GenerateGame(int x, int y, int bombratePercent) + { + Map = new IField[x, y]; + for (int i = 0; i < x; i++) + { + for (int j = 0; j < y; j++) + { + var field = new Field + { + ContainsBomb = IsBomb(bombratePercent) + }; + Map[i, j] = field; + } + } + } + + public void GenerateGame(int x, int y) + { + GenerateGame(x, y, 10); + } + } }