示例#1
0
        // Initiate a new game
        private void newGameBtn_Click(object sender, EventArgs e)
        {
            // Variables to pass to the constructor in GameField
            int iRow = 0, iCol = 0, bombs = 0;

            if (miSmallBoardSize.Checked)
            {
                iRow = 9;
                iCol = 9;
            }

            if (miMediumBoardSize.Checked)
            {
                iRow = 18;
                iCol = 18;
            }

            if (miLargeBoardSize.Checked)
            {
                iRow = 30;
                iCol = 30;
            }

            if (miUserDefinedBoardSize.Checked)
            {
                iRow = uds.RowSize;
                iCol = uds.ColumnSize;
            }

            if (iRow == 0 || iCol == 0)
            {
                MessageBox.Show("Check boardsize!", "Error");
                return;
            }

            // Calculate amount of bombs based on difficulty and boardsize
            int size = iRow*iCol;

            if (miEasyDifficulty.Checked)
                bombs = size/14;

            if (miMediumDifficulty.Checked)
                bombs = size/10;

            if (miHardDifficulty.Checked)
                bombs = size/6;

            gameField = new GameField(iRow, iCol, bombs, pPlayBoard);
            firstClick = true;
            gameField.Start();
            GameTick();

            Height = gameMenuStrip.Height + pPlayBoard.Height;
            Width = pPlayBoard.Width;
        }