Exemplo n.º 1
0
        public MineField(int width, int height, int totalMines, bool isResolvable, MinePutterDifficulty minePutterDifficulty)
        {
            Width        = width;
            Height       = height;
            IsResolvable = isResolvable;
            TotalMines   = totalMines;
            // Seed = (int) GetCurrentUnixTimestampSeconds();
            Random      = new Random();
            _minePutter = new MinePutterFactory().Generate(minePutterDifficulty);

            if (width <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(Width), "Width cannot be less or equal to zero");
            }
            if (height <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(Height), "Height cannot be less or equal to zero");
            }
            if (totalMines <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(TotalMines), "Total mines cannot be less or equal to zero");
            }
            if (totalMines >= TotalCells)
            {
                throw new ArgumentOutOfRangeException(nameof(TotalCells), "Total mines cannot be greater or equal to total cells");
            }

            Cells = new FieldCell[height, width];
        }
Exemplo n.º 2
0
        private FieldCell[,] CloneCells(FieldCell[,] oldCells)
        {
            var cells = new FieldCell[Height, Width];

            for (int i = 0; i < Height; i++)
            {
                for (int j = 0; j < Width; j++)
                {
                    var cell = oldCells[i, j];

                    cells[i, j] = (FieldCell)cell.Clone();
                }
            }

            return(cells);
        }
Exemplo n.º 3
0
        public void Generate()
        {
            _isFirstTurn   = true;
            MinesLeft      = TotalMines;
            FreeCellsLeft  = Width * Height - MinesLeft;
            TotalOpenCells = 0;

            for (int i = 0; i < Height; i++)
            {
                for (int j = 0; j < Width; j++)
                {
                    Cells[i, j] = new FieldCell(FieldCellType.NotMine, 0);
                }
            }

            Changed?.Invoke(this, EventArgs.Empty);
        }
Exemplo n.º 4
0
            public Rectangle GetSourceRectForCell(FieldCell cell)
            {
                if (cell.IsFlagged)
                {
                    return(_rectangles[_tileCountW * _tileCountH - 2]);
                }
                if (!cell.IsOpen)
                {
                    return(_rectangles[_tileCountW * _tileCountH - 3]);
                }
                if (cell.IsMine)
                {
                    return(_rectangles[_tileCountW * _tileCountH - 1]);
                }

                return(_rectangles[cell.MinesAround]);
            }
Exemplo n.º 5
0
 public PlayerTurnSnapshot(Point position, FieldCell newCellState, FieldCell oldCellState)
 {
     Position     = position;
     NewCellState = newCellState;
     OldCellState = oldCellState;
 }