public void SaveScore(IPlayer player) { List <IPlayer> playerList = this.CreateOrRetrieve(); if (playerList == null) { string[] scores = new string[1]; scores[0] = player.Name + "@" + player.Score; File.WriteAllLines(this.currentDir + this.fileName, scores); } else { playerList.Add(player); playerList.Sort(); playerList.Reverse(); if (playerList.Count > 10) { playerList.RemoveRange(9, playerList.Count - 1); } string[] scores = PlayerAdapter.PlayerToScore(playerList); File.WriteAllLines(this.currentDir + this.fileName, scores); } }
/* * * Crea o recupera el archivo para guardar los Scores de los jugadores * */ public List <IPlayer> CreateOrRetrieve() { List <IPlayer> playerList = null; if (File.Exists(this.currentDir + this.fileName)) { string[] scores = File.ReadAllLines(this.currentDir + this.fileName); if (scores.Length != 0) { playerList = PlayerAdapter.ScoreToPlayer(scores); } } else { FileStream fileStream = File.Create(this.currentDir + this.fileName); fileStream.Close(); } return(playerList); }