Пример #1
0
        public MineSweeper(int columns, int rows, int mines, int firstFieldX, int firstFieldY)
        {
            _numberOfColumns = columns;
            _numberOfRows    = rows;

            _fields = new MineField[_numberOfColumns, _numberOfRows];

            for (var i = 0; i < _numberOfColumns; i++)
            {
                for (var j = 0; j < _numberOfRows; j++)
                {
                    _fields[i, j] = new MineField();
                }
            }

            CheckCoordinates(firstFieldX, firstFieldY);

            var random = new Random();

            for (var i = 0; i < mines; i++)
            {
                int x, y;
                do
                {
                    x = random.Next(0, _numberOfColumns);
                    y = random.Next(0, _numberOfRows);
                } while (_fields[x, y].HasMine || (x == firstFieldX && y == firstFieldY));
                _fields[x, y].HasMine = true;
            }
        }
Пример #2
0
        public MineSweeper(int columns, int rows, int mines, int firstFieldX, int firstFieldY)
        {
            _numberOfColumns = columns;
            _numberOfRows = rows;

            _fields = new MineField[_numberOfColumns, _numberOfRows];

            for (var i = 0; i < _numberOfColumns; i++)
            {
                for (var j = 0; j < _numberOfRows; j++)
                {
                    _fields[i, j] = new MineField();
                }
            }

            CheckCoordinates(firstFieldX, firstFieldY);

            var random = new Random();

            for(var i = 0; i < mines; i++)
            {
                int x, y;
                do
                {
                    x = random.Next(0, _numberOfColumns);
                    y = random.Next(0, _numberOfRows);
                } while (_fields[x, y].HasMine || (x == firstFieldX && y == firstFieldY));
                _fields[x, y].HasMine = true;
            }
        }