Ejemplo n.º 1
0
 public static void CheckResultRecords()
 {
     if (Records.CheckForRecordResult(score))
     {
         Console.Clear();
         Console.SetCursorPosition(18, 9);
         Console.ForegroundColor = ConsoleColor.Red;
         Console.WriteLine("You've got a great result! Congratulations!!!");
         Console.SetCursorPosition(18, 13);
         Console.ForegroundColor = ConsoleColor.Green;
         Console.Write("Please, enter your name without spaces: ");
         Console.ForegroundColor = ConsoleColor.White;
         Console.CursorVisible   = true;
         string name = Console.ReadLine();
         Console.CursorVisible = false;
         RecordsEntry entry = new RecordsEntry();
         if (name.Contains(' '))
         {
             string[] res = name.Trim().Split();
             name = res[0];
         }
         entry.Name  = name;
         entry.Score = score;
         Records.EnterRecords(entry);
     }
 }
Ejemplo n.º 2
0
 public static void EnterRecords(RecordsEntry entry)
 {
     entries.Add(entry);
     if (entries.Count > 10)
     {
         int min = int.MaxValue;
         int pos = 0;
         for (int i = 0; i < entries.Count; i++)
         {
             if (entries[i].Score < min)
             {
                 min = entries[i].Score;
                 pos = i;
             }
         }
         entries.RemoveAt(pos);
     }
     SaveRecords();
 }
Ejemplo n.º 3
0
 private static void GetRecords()
 {
     entries.Clear();
     if (File.Exists(file))
     {
         StreamReader read = new StreamReader(file);
         using (read)
         {
             string line = read.ReadLine();
             while (line != null)
             {
                 string[]     res   = line.Split();
                 RecordsEntry entry = new RecordsEntry();
                 entry.Name  = res[0];
                 entry.Score = int.Parse(res[1]);
                 entries.Add(entry);
                 line = read.ReadLine();
             }
         }
     }
 }