Beispiel #1
0
        public void OpenSurroundingCells(int column, int row)
        {
            int sideLength = _gameField.ColumnCount;

            int sideWidth  = column + 1;
            int sideHeight = row + 1;

            for (int i = row - 1; i <= sideHeight; i++)
            {
                for (int j = column - 1; j <= sideWidth; j++)
                {
                    if (i < 0 || j < 0 || i >= sideLength || j >= sideLength)
                    {
                        continue;
                    }

                    CellButton button = _gameField.GetControlFromPosition(j, i) as CellButton;

                    if (button != null && !button.IsFlagged())
                    {
                        _presenter.FieldButtonLeftClick(button, new MouseEventArgs(MouseButtons.Left, 1, 0, 0, 0));
                    }
                }
            }
        }
Beispiel #2
0
        public void CreateField(int rowsCount, int columnsCount, int bombsCount)
        {
            if (_gameField != null)
            {
                _gameField.Dispose();
            }

            int fieldLength = 30;

            _gameField                 = new TableLayoutPanel();
            _gameField.ColumnCount     = columnsCount;
            _gameField.RowCount        = rowsCount;
            _gameField.CellBorderStyle = TableLayoutPanelCellBorderStyle.Single;
            _gameField.Margin          = new Padding(0);
            _gameField.Padding         = new Padding(0);
            _gameField.Width           = columnsCount * fieldLength;
            _gameField.Height          = rowsCount * fieldLength;
            _gameField.AutoSize        = true;
            _gameField.TabIndex        = 0;
            _gameField.BackColor       = Color.White;

            for (int y = 0; y < rowsCount; y++)
            {
                _gameField.RowStyles.Add(new RowStyle(SizeType.Absolute, fieldLength));

                for (int x = 0; x < columnsCount; x++)
                {
                    _gameField.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, fieldLength));

                    CellButton button = new CellButton(x, y, fieldLength);

                    button.MouseDown   += new MouseEventHandler(_presenter.FieldButtonLeftClick);
                    button.MouseDown   += new MouseEventHandler(_presenter.FieldButtonRightClick);
                    button.CellFlagged += new EventHandler(DecreaseBombsCounter);
                    button.CellCleared += new EventHandler(IncreaseBombsCounter);

                    _gameField.Controls.Add(button, x, y);
                }
            }

            gameFieldPanel.Controls.Add(_gameField);

            BombsCounter = bombsCount;
        }
Beispiel #3
0
        public void ClearCell(object control)
        {
            CellButton currentButton = control as CellButton;

            currentButton.Dispose();
        }