// Method that finishes the game after player has won it private void GameWon() { dTimer.Stop(); foreach (FieldUnit fu in listOfUnits) { fu.IsEnabled = false; if (fu.Bomb && !fu.Flag) { fu.Flag = true; mineCounter--; txtMineCounter.Text = mineCounter.ToString(); fu.Content = new Image { Source = new BitmapImage(new Uri("Resources/flag.png", UriKind.Relative)), VerticalAlignment = VerticalAlignment.Center }; } } // Putting smiley won image onto smiley button btnSmiley.Content = new Image { Source = new BitmapImage(new Uri("Resources/Smiley-won.png", UriKind.Relative)), VerticalAlignment = VerticalAlignment.Center }; // Expanding the smiley button after game has been won Smileybtn_animation(); // Creating new score and filename Score newScore = new Score(playerName, difficulty, timer); string fileName = "sb" + difficulty; // Reading and writing list of scores to the file if (File.Exists(fileName)) { List <Score> listOfScores = Score.ReadScores(fileName); listOfScores.Add(newScore); listOfScores.Sort(); listOfScores.RemoveAt(10); Score.WriteScores(listOfScores, fileName); } else { List <Score> listOfScores = new List <Score>(); listOfScores.Add(newScore); for (int i = 0; i < 9; i++) { listOfScores.Add(new Score()); } Score.WriteScores(listOfScores, fileName); } }
// Method that updates scoreboard stackpanel with scores public static void UpdateScoreBoard(string category) { string fileName = "sb" + category; List <Score> listOfScores = new List <Score>(); if (File.Exists(fileName)) { listOfScores = Score.ReadScores(fileName); } else { for (int i = 0; i < 10; i++) { listOfScores.Add(new Score()); } } spName.Children.Clear(); spTime.Children.Clear(); foreach (Score score in listOfScores) { spName.Children.Add(new TextBlock { Text = "Name: " + score.PlayerName }); if (score.Score_time == 999) { spTime.Children.Add(new TextBlock { Text = "Time: N/A" }); } else { spTime.Children.Add(new TextBlock { Text = "Time: " + score.Score_time.ToString() }); } } }