public HighscoreDialogViewModel(HighscoreDialog HighscoreDialog) { highscoreDialog = HighscoreDialog; using (HighscoresContext db = new HighscoresContext()) { HighscoresList = db.Highscores.OrderBy(x => x.Time).ThenBy(x => x.Moves).Take(3).ToList(); } }
public void ResetExecute() { using (HighscoresContext db = new HighscoresContext()) { foreach (var score in db.Highscores) { db.Highscores.Remove(score); } db.SaveChanges(); HighscoresList = db.Highscores.ToList(); } }
public void SaveHighscoreExecute() { highscore.Name = enterHighscore.EnterName.Text; using (HighscoresContext db = new HighscoresContext()) { db.Entry(highscore).State = EntityState.Modified; db.SaveChanges(); } enterHighscore.Close(); HighscoreDialog hd = new HighscoreDialog(); hd.ShowDialog(); }
private async void PlayMove(object p) { if (!twoFieldsOpened) { images[(int)p - 1].Visibility = System.Windows.Visibility.Visible; for (int i = 0; i < numberOfFields; i++) { if (images[i].Visibility == System.Windows.Visibility.Visible && i != ((int)p - 1)) { twoFieldsOpened = true; Task wait = Task.Delay(timeDelay); await wait; images[i].Visibility = System.Windows.Visibility.Collapsed; images[(int)p - 1].Visibility = System.Windows.Visibility.Collapsed; twoFieldsOpened = false; moves++; mainWindow.Moves.Text = moves.ToString(); if (images[i].Source.ToString().Equals(images[(int)p - 1].Source.ToString())) { buttons[i].Visibility = System.Windows.Visibility.Collapsed; buttons[(int)p - 1].Visibility = System.Windows.Visibility.Collapsed; if (End()) { Highscores highscore = new Model.Highscores(); highscore.Name = "Player"; highscore.Time = int.Parse(mainWindow.Time.Text); highscore.Moves = int.Parse(mainWindow.Moves.Text); using (HighscoresContext db = new HighscoresContext()) { db.Highscores.Add(highscore); db.SaveChanges(); if (db.Highscores.OrderBy(x => x.Time).ThenBy(x => x.Moves).Take(3).ToList().Contains(highscore)) { EnterHighscore eh = new EnterHighscore(highscore); eh.ShowDialog(); } } dispatcherTimer.Stop(); dispatcherTimer.IsEnabled = false; } } } } } }