internal static IGameboard GenerateFieldWithSizeTwo() { var gameboard = new Gameboard(2); gameboard[0, 0] = new Mine(MineRadius.MineRadiusOne); gameboard[0, 1] = new EmptyCell(); gameboard[0, 1].Explode(); gameboard[1, 0] = new EmptyCell(); gameboard[1, 1] = new EmptyCell(); return gameboard; }
private void GenerateMinesInField(IGameboard gameboard, int minesCount) { int size = gameboard.Size; Array mineRadiusValues = Enum.GetValues(typeof(MineRadius)); int mineRadiusMaxIndex = mineRadiusValues.Length - 1; List<Position> usedPositions = new List<Position>(); while (usedPositions.Count < minesCount) { int cellX = this.rand.GetRandom(0, size - 1); int cellY = this.rand.GetRandom(0, size - 1); Position position = new Position(cellX, cellY); if (usedPositions.Contains(position)) { continue; } usedPositions.Add(position); int cellType = this.rand.GetRandom(0, mineRadiusMaxIndex); MineRadius randomRadius = (MineRadius)mineRadiusValues.GetValue(cellType); ICell currentCell = new Mine(randomRadius); gameboard[cellX, cellY] = currentCell; } }