Changed Type of the key in scoreboard from Player to string
continuous-integration/drone/push Build is failing Details

test_old_branch
Jules LASCRET 11 months ago
parent 0437e4a184
commit 3bd5625035

@ -30,9 +30,9 @@ namespace QwirkleClassLibrary.Games
private readonly List<Player> players = [];
[DataMember]
private readonly Dictionary<Player, int> scoreBoard = [];
private readonly Dictionary<string, int> scoreBoard = [];
public ReadOnlyDictionary<Player, int> ScoreBoard => scoreBoard.AsReadOnly();
public ReadOnlyDictionary<string, int> ScoreBoard => scoreBoard.AsReadOnly();
[DataMember]
private readonly List<Cell> 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;
}

@ -21,13 +21,13 @@ namespace QwirkleClassLibrary.Players
/// <summary>
/// Returns the index of the player in the leaderboard, -1 if the player is not in the leaderboard
/// </summary>
/// <param name="player"></param>
/// <param name="playerTag"></param>
/// <returns>int</returns>
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
/// </summary>
/// <param name="scoreBoard"></param>
public void AddScoreInLead(ReadOnlyDictionary<Player, int> scoreBoard)
public void AddScoreInLead(ReadOnlyDictionary<string, int> 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<Player, int> pair in sb)
foreach (KeyValuePair<string, int> 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);
}

@ -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<Player, int> pair in sb)
foreach (KeyValuePair<string, int> pair in sb)
{
i++;
WriteLine("[" + i + "] " + pair.Key.NameTag + " with " + pair.Value.ToString() + " points.");
WriteLine("[" + i + "] " + pair.Key + " with " + pair.Value.ToString() + " points.");
}
}

@ -54,11 +54,11 @@ namespace TestBase
[Fact]
public void Test_LoadLeaderboard()
{
var scoreboard = new Dictionary<Player, int>()
var scoreboard = new Dictionary<string, int>()
{
{ 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();

Loading…
Cancel
Save