コード例 #1
0
 public EnterHighscoreViewModel(EnterHighscore EnterHighscore, Highscores Highscore)
 {
     enterHighscore = EnterHighscore;
     highscore      = Highscore;
     enterHighscore.EnterName.Text = highscore.Name;
     enterHighscore.EnterName.SelectAll();
     enterHighscore.EnterName.Focus();
 }
コード例 #2
0
        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;
                            }
                        }
                    }
                }
            }
        }