added GameGeneration

This commit is contained in:
Tim Wundenberg
2018-05-25 09:52:42 +02:00
parent bf287ec760
commit 764f98b7e0
2 changed files with 37 additions and 1 deletions

View File

@@ -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; }
}
}

View File

@@ -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);
}
}
}