diff --git a/Qwirkle/QwirkleClassLibrary/Games/Game.cs b/Qwirkle/QwirkleClassLibrary/Games/Game.cs index c1b9d3a..db72c31 100644 --- a/Qwirkle/QwirkleClassLibrary/Games/Game.cs +++ b/Qwirkle/QwirkleClassLibrary/Games/Game.cs @@ -30,9 +30,9 @@ namespace QwirkleClassLibrary.Games private readonly List players = []; [DataMember] - private readonly Dictionary scoreBoard = []; + private readonly Dictionary scoreBoard = []; - public ReadOnlyDictionary ScoreBoard => scoreBoard.AsReadOnly(); + public ReadOnlyDictionary ScoreBoard => scoreBoard.AsReadOnly(); [DataMember] private readonly List cellUsed = []; @@ -104,7 +104,7 @@ namespace QwirkleClassLibrary.Games { Player pl = CreatePlayer(tag); players.Add(pl); - scoreBoard.Add(pl, 0); + scoreBoard.Add(pl.NameTag, 0); } OnPlayerNotified(new AddPlayerNotifiedEventArgs("Players were correctly added.")); @@ -619,9 +619,9 @@ namespace QwirkleClassLibrary.Games score += 6; } - if (!scoreBoard.TryAdd(player, score)) + if (!scoreBoard.TryAdd(player.NameTag, score)) { - scoreBoard[player] += score; + scoreBoard[player.NameTag] += score; } return score; @@ -773,7 +773,7 @@ namespace QwirkleClassLibrary.Games { OnEndOfGame(new EndOfGameNotifiedEventArgs(player)); GameRunning = false; - scoreBoard[player] += 6; + scoreBoard[player.NameTag] += 6; return true; } diff --git a/Qwirkle/QwirkleClassLibrary/Players/Leaderboard.cs b/Qwirkle/QwirkleClassLibrary/Players/Leaderboard.cs index db9a0b6..e77bda7 100644 --- a/Qwirkle/QwirkleClassLibrary/Players/Leaderboard.cs +++ b/Qwirkle/QwirkleClassLibrary/Players/Leaderboard.cs @@ -21,13 +21,13 @@ namespace QwirkleClassLibrary.Players /// /// Returns the index of the player in the leaderboard, -1 if the player is not in the leaderboard /// - /// + /// /// int - public int IsPlayerIn(Player player) + public int IsPlayerIn(string playerTag) { for (int i = 0; i < leaderboard.Count; i++) { - if (player.NameTag == leaderboard[i].PlayerName) + if (playerTag == leaderboard[i].PlayerName) { return i; } @@ -39,13 +39,13 @@ namespace QwirkleClassLibrary.Players /// Adds the score of the players in the leaderboard with the date of the day and the number of victories /// /// - public void AddScoreInLead(ReadOnlyDictionary scoreBoard) + public void AddScoreInLead(ReadOnlyDictionary scoreBoard) { DateTime now = DateTime.Now; bool first = true; - var sb = scoreBoard.OrderByDescending(x => x.Value).ThenBy(x => x.Key.NameTag); + var sb = scoreBoard.OrderByDescending(x => x.Value).ThenBy(x => x.Key); - foreach (KeyValuePair pair in sb) + foreach (KeyValuePair pair in sb) { int i = IsPlayerIn(pair.Key); @@ -72,7 +72,7 @@ namespace QwirkleClassLibrary.Players { v = 1; } - Score score = new Score(pair.Key.NameTag, now, pair.Value, v); + Score score = new Score(pair.Key, now, pair.Value, v); leaderboard.Add(score); } diff --git a/Qwirkle/QwirkleConsoleApp/Program.cs b/Qwirkle/QwirkleConsoleApp/Program.cs index a02170a..4e3ae2e 100644 --- a/Qwirkle/QwirkleConsoleApp/Program.cs +++ b/Qwirkle/QwirkleConsoleApp/Program.cs @@ -259,12 +259,12 @@ static void ShowScoreBoard(Game g) int i = 0; - var sb = g.ScoreBoard.OrderByDescending(x => x.Value).ThenBy(x => x.Key.NameTag); + var sb = g.ScoreBoard.OrderByDescending(x => x.Value).ThenBy(x => x.Key); - foreach (KeyValuePair pair in sb) + foreach (KeyValuePair pair in sb) { i++; - WriteLine("[" + i + "] " + pair.Key.NameTag + " with " + pair.Value.ToString() + " points."); + WriteLine("[" + i + "] " + pair.Key + " with " + pair.Value.ToString() + " points."); } } diff --git a/Qwirkle/TestBase/TestPersistence.cs b/Qwirkle/TestBase/TestPersistence.cs index cf29910..fac5837 100644 --- a/Qwirkle/TestBase/TestPersistence.cs +++ b/Qwirkle/TestBase/TestPersistence.cs @@ -54,11 +54,11 @@ namespace TestBase [Fact] public void Test_LoadLeaderboard() { - var scoreboard = new Dictionary() + var scoreboard = new Dictionary() { - { new Player("Rémy"), 60 }, - { new Player("Jérémy"), 50 }, - { new Player("Jules"), 100 } + { "Rémy", 60 }, + { "Jérémy", 50 }, + { "Jules", 100 } }; var scoreboardro = scoreboard.AsReadOnly();