public static void SaveRecords(string playerName) { List <ScoreRecordItem> recordsArray = LoadScoreRecords(); bool isNameExistsInRecords = false; for (int i = 0; i < recordsArray.Count; i++) { if (playerName == recordsArray[i].UserName) { isNameExistsInRecords = true; if (BoardController.score > recordsArray[i].Score) { recordsArray.RemoveAt(i); recordsArray.Add(ScoreRecordItem.StringToRecordItem(playerName + "|" + BoardController.score)); } } } if (!isNameExistsInRecords) { recordsArray.Add(ScoreRecordItem.StringToRecordItem(playerName + "|" + BoardController.score)); } List <string> recordsStringArray = new List <string>(); foreach (var rec in recordsArray) { recordsStringArray.Add(rec.ToString()); } File.WriteAllLines(scoresRecordsPath, recordsStringArray); }
public static List <ScoreRecordItem> LoadScoreRecords() { string[] recordsStringArray = File.ReadAllLines(scoresRecordsPath); List <ScoreRecordItem> recordsArray = new List <ScoreRecordItem>(); foreach (var rec in recordsStringArray) { recordsArray.Add(ScoreRecordItem.StringToRecordItem(rec)); } return(recordsArray); }