Exemplo n.º 1
0
 private void writeEntry(ScoreEntry entry)
 {
     string towrite = entry.getName() + ":" + entry.getLevel();
     FileInfo fi = new FileInfo(this.fileName);
     System.IO.StreamWriter file = fi.AppendText();
     file.WriteLine(towrite);
     file.Close();
 }
Exemplo n.º 2
0
 private ScoreEntry[] readFile()
 {
     ScoreEntry[] entr = new ScoreEntry[this.maxEntries];
     if(!File.Exists(this.fileName)) {
         return (new ScoreEntry[this.maxEntries]);
     }
     using(StreamReader sr = File.OpenText(this.fileName)) {
         List<ScoreEntry> scores = new List<ScoreEntry>();
         string line;
         while((line = sr.ReadLine()) != null) {
             if(!line.Contains(":")) { //crude validity check
                 break;
             }
             scores.Add(new ScoreEntry(line.Split(':')[0], Convert.ToInt32(line.Split(':')[1])));
         }
         scores = scores.OrderBy(s => s.getLevel()).ToList();
         scores.Reverse();
         for(int i = 0; ((i < scores.Count) && (i < this.maxEntries)); i++) {
             entr[i] = scores.ElementAt(i);
         }
     }
     return entr;
 }