public void AddToHighScores(Player player) { //without this piece there is (apparently) a chance of the application breaking //the constructor does not construct this for me. No idea why, no, not my fault. I cloned dev. if (this.HighScores == null) { this.HighScores = new List <HighScoreListing>(); } /* * Add to the highscores list */ HighScoreListing listing = new HighScoreListing { Name = player.Name, Score = player.ScoreBoard.Score }; this.HighScores.Add(listing); /* * Convert the list to JSON */ string json = JsonConvert.SerializeObject(this.HighScores, Newtonsoft.Json.Formatting.Indented); /* * Create the filepath and write the encrypted JSON format to file */ Files.Create(this.HighScorespath); /* * In WriteToFile we apparently encrypt as well. * Not entirely sure why, I will have to ask for clarification */ Files.WriteToFile(this.HighScorespath, json); }
public void AddToHighScores(Player player) { HighScoreListing listing = new HighScoreListing(player.Name, player.ScoreBoard.Score); this.highScores.Add(listing); string json = JsonConvert.SerializeObject(this.highScores); Files.WriteToFile((Path.Combine(Directory.GetCurrentDirectory(), "highscores.txt")), json); }