コード例 #1
0
        /// <summary>
        /// Initialize the form
        /// </summary>
        public MainForm()
        {
            // Create default values the variables
            mGame             = new Game(this);
            mHighscoreEntries = new List <HighscoreEntry>();
            mIsRunning        = false;

            // Try to read the highscore file (don't want an error if the file don't exists as it will if so be created when a entry is saved)
            try
            {
                if (File.Exists(mHighscoreFile))
                {
                    mHighscoreEntries = BinSerializerUtility.DeSerialize <List <HighscoreEntry> >(mHighscoreFile);
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.ToString());
            }

            // Create a game timer to measure amount time between frames (delta time)
            mGameTimer = new Stopwatch();
            mGameTimer.Start();

            InitializeComponent();
            InitializeGUI();
        }
コード例 #2
0
        /// <summary>
        /// Event that will check if the Submit button is pressed at the endscreen form
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void endScreenSubmitButton_Click(object sender, EventArgs e)
        {
            // If the name is not empty
            if (endScreenNameInput.Text != String.Empty)
            {
                // Create a highscore entry
                mHighscoreEntries.Add(new HighscoreEntry(endScreenNameInput.Text, (mGame.GetMap().GetMaxFood() - mGame.GetMap().GetFoodLeft())));
                UpdateHighscores();

                // Try to save the highscores
                try
                {
                    BinSerializerUtility.Serialize(mHighscoreEntries, mHighscoreFile);
                }
                catch (Exception exception)
                {
                    MessageBox.Show(exception.ToString());
                }

                //Hide the end screen form and show the main form
                endScreenGroupBox.Visible = false;
                mainGroupBox.Visible      = true;
            }
            else
            {
                MessageBox.Show("Please enter a valid name!");
            }
        }