public void addHighScore(string name, int cave, int score) { // (name, cave #, score) HighScore h1 = new HighScore(name, cave, score); scores.Add(h1); // Sort the list in decreasing order for (int i = 0; i < scores.Count; i++) { HighScore hScore = scores[i]; for (int j = i + 1; j < scores.Count; j++) { HighScore hScore2 = scores[j]; if (hScore.Score < hScore2.Score) { scores[i] = scores[j]; scores[j] = hScore; hScore = scores[i]; } } } // This is to make sure only the top ten highest scores are // displayed. if (scores.Count > 10) scores.RemoveAt(10); // put write file method here. }
public void readFile() { StreamReader sr = new StreamReader("HighScoreData.txt"); //read in a line of data from the text file string input = sr.ReadLine(); while (input != null) { string[] data = input.Split(','); //fill out the info for the song object string nameString; int caveNumberInt; int scoreInt; nameString = data[0]; caveNumberInt = int.Parse(data[1]); scoreInt = int.Parse(data[2]); HighScore s = new HighScore(nameString, caveNumberInt, scoreInt); //recreate the list array scores.Add(s); //get the next line of data input = sr.ReadLine(); } sr.Close(); }