added GameGeneration
This commit is contained in:
@@ -7,6 +7,11 @@ namespace CoopSweeper.GameTypes
|
||||
|
||||
class Field : IField
|
||||
{
|
||||
public Field()
|
||||
{
|
||||
State = FieldState.NONE;
|
||||
}
|
||||
|
||||
public bool ContainsBomb { get; set; }
|
||||
|
||||
public FieldState State { get; set; }
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user