Fix crash if list is empty

This commit is contained in:
2019-05-04 18:26:21 +02:00
parent 4db2348049
commit 72c1fdf787

View File

@@ -23,18 +23,24 @@ namespace LobbyServer
else else
{ {
_scores = new List<ScoreEntry>(); _scores = new List<ScoreEntry>();
_scores.Add(new ScoreEntry("QuadraLudi", 0));
} }
} }
public void Add(ScoreEntry entry) public void Add(ScoreEntry entry)
{ {
_scores.Add(entry); _scores.Add(entry);
_scores.OrderByDescending(x => x.Score); Sort();
} }
public void Save() public void Save()
{ {
File.WriteAllText(FilePath, JsonConvert.SerializeObject(_scores)); File.WriteAllText(FilePath, JsonConvert.SerializeObject(_scores));
} }
private void Sort()
{
_scores = _scores.OrderByDescending(x => x.Score).ToList();
}
} }
} }