Exemple #1
0
        void GameOver()
        {
            IsGameOver = true;

            _gameTimer.Stop();
            _actionTimer.Stop();

            var scoreAsk = MessageBox.Show("Game over! Would you like to submit your score?", "Game Over!", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);

            if (scoreAsk == DialogResult.Yes)
            {
                using (var context = new HighScoreContext())
                {
                    context.HighScores.Add(new HighScore()
                    {
                        Entered     = DateTime.UtcNow,
                        Name        = _settings.PlayerName,
                        Difficulty  = _settings.Difficulty.ToString(),
                        Score       = TotalPoints,
                        TotalMoles  = _totalMolesSeen,
                        TotalHit    = _totalMolesHit,
                        TotalMissed = _totalMolesMissed
                    });
                    context.SaveChanges();
                }

                var hsForm = new HighScores();
                hsForm.ShowDialog();
            }

            Close();
        }
 void SetupControls()
 {
     using (var context = new HighScoreContext())
     {
         var scores = context.HighScores.OrderByDescending(x => x.Id).ToList();
         scores.ForEach(score => {
             dataGrid.Rows.Add(score.Entered.ToShortDateString(), score.Name, score.Difficulty, score.TotalMoles, score.TotalHit, score.TotalMissed, score.Score);
         });
     }
 }
Exemple #3
0
 void ClearHighScores()
 {
     // This is by far the worst way of doing this.
     using (var context = new HighScoreContext())
     {
         var entities = context.HighScores;
         context.HighScores.RemoveRange(entities);
         context.SaveChanges();
     }
 }