/// <summary> /// Add item to the list. /// </summary> /// <param name="item"></param> /// <returns>True if item made it in the top 5, False in not.</returns> public bool add(HighScoreItem item) { highScores.Add(item); highScores.Sort(); if (highScores.Count > 5) { bool madeit = false; HighScores temp = new HighScores(); for (int i = 0; i < 5; i++) { temp.highScores[i] = this.highScores[i]; if (temp.highScores[i].Equals(item)) { madeit = true; } } this.highScores = temp.highScores; return madeit; } else { return true; } }
//Tests each score to see if it is greater than a current high score then calls method to alter the file public void UpdateHighScoreList(string score) { int result = int.Parse(score); DateTime date = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day); for (int i = 0; i < HighScores.Count; i++) { if (result > int.Parse(HighScores[i]) && result != 0) { HighScores.Insert(i, result.ToString()); HighScores.RemoveAt(10); DatesOfHighScores.Insert(i, date); DatesOfHighScores.RemoveAt(10); result = 0; WriteToFile(HighScores, DatesOfHighScores); } } }