Beispiel #1
0
        }                                                      //END (FormSettings_FormClosing)

        #endregion

        #region Form controls events handlers
        /// <summary>
        /// Close button click event handler
        /// </summary>
        /// <param name="sender">Event sender</param>
        /// <param name="e">Event arguments</param>
        private void butClose_Click(object sender, EventArgs e)
        {
            if (rbNewbie.Checked)                            //if Newbie radiobutton is checked
            {
                formParent.MS = MinesSettings.setSettings(   //set new game settings
                    MinesSettings.Preset.Newbie,             //preset: Newbie
                    cbUseQuestionMarks.Checked);             //questions: equals checkbox state
            }                                                //ENDIF (newbie)
            else if (rbAdvanced.Checked)                     //if Advanced radiobutton is checked
            {
                formParent.MS = MinesSettings.setSettings(   //set new game settings
                    MinesSettings.Preset.Advanced,           //preset: Advanced
                    cbUseQuestionMarks.Checked);             //questions: equals checkbox state
            }                                                //END (advanced)
            else if (rbProfessional.Checked)                 //if Professional radiobutton is checked
            {
                formParent.MS = MinesSettings.setSettings(   //set new game settings
                    MinesSettings.Preset.Professional,       //preset: Professional
                    cbUseQuestionMarks.Checked);             //questions: equals checkbox state
            }                                                //END (professional)
            else if (rbCustom.Checked)                       //if Custom radiobutton is checked
            {
                formParent.MS = MinesSettings.setSettings(   //set new game settings
                    (int)nudWidth.Value,                     //width equals Width box
                    (int)nudHeight.Value,                    //height equals Height box
                    (uint)nudMines.Value,                    //mines equals Mines box
                    cbUseQuestionMarks.Checked);             //questions: equals checkbox state
            }                                                //END (custom)
            else                                             //if somehow no radiobutton is checked
            {
                formParent.MS = MinesSettings.setSettings(); //set default game settings
            }
            Close();                                         //close Settings form
        }                                                    //END (butClose_Click)
Beispiel #2
0
        }   //END (ctor)

        /// <summary>
        /// Main form load handler
        /// </summary>
        /// <param name="sender">Sender of the form load event</param>
        /// <param name="e">Form load event args</param>
        private void FormMineSweeper_Load(object sender, EventArgs e)
        {
            //loading game settings
            try                                     //trying to load settings from the file
            {
                FileStream fs = new FileStream("minesettings.soap", FileMode.Open);
                //using SOAP-serialization
                SoapFormatter formatter = new SoapFormatter();
                MS = (MinesSettings)formatter.Deserialize(fs);
                //disposing the file-stream
                fs.Dispose();
                fs = null;
            }   //ENDTRY
            catch (FileNotFoundException)           //if game-settings file wasn't found
            {
                MS = MinesSettings.setSettings();   //loading default settings
            }   //ENDCATCH (File not found)
            catch (SerializationException)          //if something went wrong with serialization
            {
                MS = MinesSettings.setSettings();   //loading default settings
            }   //ENDCATCH (Serialization)

            //loading game stats
            try                                         //trying to load stats from the file
            {
                FileStream fs = new FileStream("minestats.soap", FileMode.Open);
                //using SOAP-serialization
                SoapFormatter formatter = new SoapFormatter();
                MStats = (MinesStatistics)formatter.Deserialize(fs);
                //disposing the file-stream
                fs.Dispose();
                fs = null;
            }   //ENDTRY
            catch (FileNotFoundException)               //if game-stats file wasn't found
            {
                MStats = MinesStatistics.getInstance(); //create empty stats
            }   //ENDCATCH (File not found
            catch (SerializationException)              //if something went wrong with serialization
            {
                MStats = MinesStatistics.getInstance(); //create empty stats
            }   //ENDCATCH (Serialization)
            
            //setting styles for the form controls
            SetStyle(ControlStyles.UserPaint, true);                //controls must be drawn by themselves (not by OS)
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);     //controls must ignore WM_ERASEBKGND message (reduces flicker)
            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);    //controls must be pre-drawn in buffer (reduces flicker)
            SetStyle(ControlStyles.ResizeRedraw, true);             //controls must be re-drawn when their size changes
            UpdateStyles();                                         //force apply the new styles

            //creating prototype mine-field label (will be used in cloning all the minefield cells)
            flPrototype = new MineFieldLabel(
                new Size(CellSize, CellSize),   //label size
                ilIconsField,                   //image list for label
                ClosedColor,                    //back color of the label
                Cell_Down,                      //mouse-down event handler
                Cell_Up,                        //mouse-up event handler
                MineFieldLabel_DoubleClick);    //double-click event handler

            //generating all the cells for the maximal-field-dimensions by using prototype label
            Array.Resize(ref FL, MinesSettings.MaxWidth);       //get memory for the field
            for(int i = 0; i < MinesSettings.MaxWidth; i++)     //moving through all the columns
            {
                Array.Resize(ref FL[i], MinesSettings.MaxHeight);   //get memory for the current field column
                for (int j = 0; j < MinesSettings.MaxHeight; j++)   //moving through all the cells in current column
                    FL[i][j] = flPrototype.GetNew(CellSize, i, j);      //create new label for the current cell
                gbMineField.Controls.AddRange(FL[i]);               //add current column of cells into the field
            }   //ENDFOR (columns)

            //initialising the mine field
            InitialiseField();
        }   //END (FormMineSweeper_Load)