public int Save(Score score) { TheScores.Add(score); TheScores = TheScores.OrderBy(s => s.ElapsedTime).ToList(); var position = TheScores.IndexOf(score) + 1; File.WriteAllText(scoresPath, JsonConvert.SerializeObject(TheScores), Encoding.UTF8); WriteLeaderBoard(position); return position; }
private void EndRound(object obj) { ShowSummary = !ShowSummary; if (ShowSummary) { ButtonText = FinishedText; stopWatch.Stop(); uiUpdateTimer.Stop(); if (obj is int) { UpdateElapsedTime(null, null); var score = new Score(stopWatch.Elapsed, Contestant, Phone); var position = competition.SaveScore(score); SummaryText = string.Format(SummaryTextSuccess, position); } else { SummaryText = SummaryTextFailed; } } else { ButtonText = RunningText; enableButtonTwo = false; ButtonTwoCommand.OnCanExecuteChanged(); competition.ResetTests(); Contestant = ""; Phone = ""; OnPropertyChanged("Running"); } }
public int SaveScore(Score score) { uiUpdateTimer.Stop(); Scores.Add(score); var position = scores.Save(score); Scores.Clear(); Scores.AddRange(scores.TheScores.Take(10)); return position; }