public IEnumerable<Tuple<string, int>> RetrieveScores(ScoreBoardVersion version, GameId gameid) { switch (version.Version) { case 1: return ScoreDataStoreFactory.GetDataStore().GetGameScores(gameid); default: throw new NotImplementedException(); } }
public void SubmitScore(ScoreBoardVersion version, GameId gameid, string username, int score) { switch (version.Version) { case 1: ScoreDataStoreFactory.GetDataStore().AddGameScore(gameid, username, score); break; default: throw new NotImplementedException(); } }
public void AddGameScore(GameId gameId, string playerName, int score) { this.allGameScores.AddOrUpdate(gameId, (key) => { Dictionary<string, int> newDictionary = new Dictionary<string, int>(); newDictionary.Add(playerName, score); return newDictionary; }, (key, dictionary) => { dictionary[playerName] = Math.Max(score, dictionary.ContainsKey(playerName) ? dictionary[playerName] : 0 ); return dictionary; }); this.AddDefaultScores(gameId); if (SeralizationEnabled) { SerializeToDisk(); } }
public IEnumerable<Tuple<string, int>> GetGameScores(GameId gameId) { if (!this.allGameScores.ContainsKey(gameId)) { this.allGameScores.TryAdd(gameId, new Dictionary<string, int>()); this.AddDefaultScores(gameId); } Dictionary<string, int> gameScores = null; if (!this.allGameScores.TryGetValue(gameId, out gameScores) || gameScores == null) { return Enumerable.Empty<Tuple<string, int>>(); } return gameScores .OrderBy(t => t.Value) .Reverse() .Select(t => new Tuple<string, int>(t.Key, t.Value)) .Take(20); }
private void AddDefaultScores(GameId game) { defaultScores.ToList().ForEach(score => { if (!allGameScores[game].ContainsKey(score.Item1)) { allGameScores[game][score.Item1] = score.Item2; } }); }