Beispiel #1
0
        public int CountSurroundingMines(Coordinates coordinates)
        {
            var surroundingCoordinates = Enumerable.Range(coordinates.RowIndex - 1, 3)
                .SelectMany(rowIndex =>
                    Enumerable.Range(coordinates.ColumnIndex - 1, 3)
                        .Select(columnIndex => new Coordinates(columnIndex: columnIndex, rowIndex: rowIndex)));

            return surroundingCoordinates
                .Count(surroundingCoordinate => !OutOfBounds(surroundingCoordinate) && IsMine(surroundingCoordinate));
        }
Beispiel #2
0
 public Grid InsertMine(Coordinates coordinates)
 {
     _grid[coordinates.ColumnIndex, coordinates.RowIndex].SetMine();
     return new Grid(Width, Height, _grid, _numMines);
 }
Beispiel #3
0
 private bool OutOfBounds(Coordinates coordinates)
 {
     return coordinates.ColumnIndex < 0 || coordinates.RowIndex < 0 || coordinates.ColumnIndex >= Width || coordinates.RowIndex >= Height;
 }
Beispiel #4
0
        public void RandomiseMines()
        {
            for (int i = 0; i < _numMines; i++)
            {

                Random rnd = new Random();
                var mineX = rnd.Next(Width - 1);
                var mineY = rnd.Next(Height - 1);
                var mineCoords = new Coordinates(mineX, mineY);

                if (IsMine(mineCoords))
                {
                    i--;
                }

                InsertMine(mineCoords);
            }
        }
Beispiel #5
0
 public bool IsMine(Coordinates coordinates)
 {
     return _grid[coordinates.ColumnIndex, coordinates.RowIndex].IsMine;
 }
Beispiel #6
0
 public bool IsExplored(Coordinates coordinates)
 {
     return _grid[coordinates.ColumnIndex, coordinates.RowIndex].Explored;
 }