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); }