示例#1
0
        /// <summary>
        /// call back method that does the scoring at the end of the game
        /// </summary>
        /// <param name="score"></param>
        private void Scoring(int score)
        {
            NameDialog dialog = new NameDialog();
            HighScore  nhs    = new HighScore();

            //Getting the name from the user via a modal dialog
            if (DialogResult.OK == dialog.ShowDialog())
            {
                //creating a new highscore
                nhs._name  = dialog.GetName;
                nhs._score = score;
            }
            //adding the new entry
            saveData.Add(nhs);
            //saveData.Sort();
            //trying to write the new list to the binary file
            try
            {
                FileStream      fs = new FileStream("Highscores.bin", FileMode.Create, FileAccess.Write);
                BinaryFormatter bf = new BinaryFormatter();
                //serializing the data
                bf.Serialize(fs, saveData);
                fs.Close();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            //sorting the data
            saveData.Sort((s1, s2) => s2._score.CompareTo(s1._score));
            //clearing the listview
            LV_HighScores.Items.Clear();
            //displaying the scores to the user
            foreach (HighScore h in saveData)
            {
                ListViewItem lvi = new ListViewItem(h._score.ToString());
                lvi.SubItems.Add(h._name);
                LV_HighScores.Items.Add(lvi);
            }
        }
示例#2
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            //graphics.PreferredBackBufferWidth = 1280;
            //graphics.PreferredBackBufferHeight = 720;
            graphics.PreferredBackBufferWidth  = 2560;
            graphics.PreferredBackBufferHeight = 720;
            //graphics.ToggleFullScreen();
            //graphics.ApplyChanges();

            screenWidth  = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width;
            screenHeight = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height;

            this.Window.Position = new Point(
                (screenWidth - graphics.PreferredBackBufferWidth) / 2,
                (screenHeight - graphics.PreferredBackBufferHeight - 32) / 2);

            screen                 = new StateManager(this);
            highScoreObject        = new HighScore(StateManager.Game);
            highScoreObject.active = false;
            screen.Push(new Screens.AttractScreen(highScoreObject));

            base.Initialize();
        }