From 764f98b7e0ca7b18112500a4db70fe6026c9f7b6 Mon Sep 17 00:00:00 2001 From: Tim Wundenberg Date: Fri, 25 May 2018 09:52:42 +0200 Subject: [PATCH] added GameGeneration --- CoopSweeper/GameTypes/Field.cs | 7 ++++++- CoopSweeper/GameTypes/Game.cs | 31 +++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) 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); + } + } }