public HighscoreEntry GetHighscoreEntry(HighscoreKey key) { // There should just be one element in this list. IEnumerable<HighscoreEntry> highscoreEntry = from k in Entries where k.Key.Diff == key.Diff where k.Key.Place == key.Place select k.Value; return highscoreEntry.ElementAt(0); }
public HighscoreEntry GetHighscoreEntry(HighscoreKey key) { // There should just be one element in this list. IEnumerable <HighscoreEntry> highscoreEntry = from k in Entries where k.Key.Diff == key.Diff where k.Key.Place == key.Place select k.Value; return(highscoreEntry.ElementAt(0)); }
public override bool Equals(object obj) { HighscoreKey hk = (HighscoreKey)obj; if ((Place == hk.Place) && (Diff == hk.Diff)) { return(true); } return(false); }
public bool AddIfHighScore(Difficulty d, int seconds) { HighscoreEntry he = new HighscoreEntry(seconds); HighscoreKey hk = new HighscoreKey(4, d); Entries[hk] = he; var myList = Entries.ToList(); myList.Sort((firstPair, secondPair) => { int diffAsIntFirst = (int)firstPair.Key.Diff; int diffAsIntSecond = (int)secondPair.Key.Diff; if (diffAsIntFirst < diffAsIntSecond) return -1; else if (diffAsIntFirst > diffAsIntSecond) return 1; return firstPair.Value.Seconds.CompareTo(secondPair.Value.Seconds); } ); // Trim the list to just 3 elements per diff list. int count = 0; Difficulty prevDiff = Difficulty.Easy; for (int i = 0; i < myList.Count; ++i) { var keyValuePair = myList.ElementAt(i); HighscoreEntry entryValue = keyValuePair.Value; HighscoreKey entryKey = keyValuePair.Key; if (entryKey.Diff == prevDiff) ++count; else count = 1; if (count > 3) { myList.RemoveAt(i); --i; continue; } prevDiff = entryKey.Diff; myList.ElementAt(i).Key.Place = count; } Entries = myList.ToDictionary(t => t.Key, t => t.Value); var listOfSimilar = (from key in Entries where key.Key.Diff == d where key.Value.Seconds == seconds select key).ToList(); if (listOfSimilar.Count > 0) return true; return false; }
public bool AddIfHighScore(Difficulty d, int seconds) { HighscoreEntry he = new HighscoreEntry(seconds); HighscoreKey hk = new HighscoreKey(4, d); Entries[hk] = he; var myList = Entries.ToList(); myList.Sort((firstPair, secondPair) => { int diffAsIntFirst = (int)firstPair.Key.Diff; int diffAsIntSecond = (int)secondPair.Key.Diff; if (diffAsIntFirst < diffAsIntSecond) { return(-1); } else if (diffAsIntFirst > diffAsIntSecond) { return(1); } return(firstPair.Value.Seconds.CompareTo(secondPair.Value.Seconds)); } ); // Trim the list to just 3 elements per diff list. int count = 0; Difficulty prevDiff = Difficulty.Easy; for (int i = 0; i < myList.Count; ++i) { var keyValuePair = myList.ElementAt(i); HighscoreEntry entryValue = keyValuePair.Value; HighscoreKey entryKey = keyValuePair.Key; if (entryKey.Diff == prevDiff) { ++count; } else { count = 1; } if (count > 3) { myList.RemoveAt(i); --i; continue; } prevDiff = entryKey.Diff; myList.ElementAt(i).Key.Place = count; } Entries = myList.ToDictionary(t => t.Key, t => t.Value); var listOfSimilar = (from key in Entries where key.Key.Diff == d where key.Value.Seconds == seconds select key).ToList(); if (listOfSimilar.Count > 0) { return(true); } return(false); }
private async void DisplayHighScore() { await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => { HighscoreKey key = new HighscoreKey(); key.Diff = _difficulty; key.Place = 1; HighscoreEntry currentEntry = _gameInfo.GetHighscoreEntry(key); HighscoresText.Text = FormatTime(currentEntry.Seconds); }); }