Esempio n. 1
0
        private void HighScore()
        {
            if (!File.Exists("highscores.xml"))
            {
                try {
                    InitHSFile();
                } catch (Exception) {
                    Cons.WriteLine("   Cannot initialize highscore.xml");
                    Cons.ReadLine();
                    Environment.Exit(0);
                }
            }

            Cons.Clear();
            Cons.WriteAscii(" Highscores", Color.DarkOrange);
            Cons.ResetColor();

            if (Highscores.Count > 0)
            {
                if (Highscores.Count > 5)
                {
                    var num = Highscores.Count - 5;
                    Highscores = Highscores.OrderByDescending(o => o.Score).ToList();
                    Highscores.RemoveRange(5, num);
                }

                var formatter = "{0,5} {1,5} {2,10} {3,10} {4,10}";
                var header    = new string[] {
                    "No",
                    "Score",
                    "Moves",
                    "Elapsed",
                    "Date"
                };
                var ordered = Highscores.OrderByDescending(o => o.Score).ToArray();
                Console.WriteLine();
                Cons.WriteLine(formatter, Color.DarkRed, header);
                for (int i = 0; i < ordered.Length; i++)
                {
                    var values = new string[] {
                        (i + 1).ToString() + '.',
                        ordered[i].Score.ToString(),
                        ordered[i].Moves.ToString(),
                        ordered[i].Elapsed,
                        ordered[i].Time
                    };
                    Cons.WriteLine(formatter, Color.DarkOrange, values);
                }
            }
            else
            {
                Cons.WriteLine("   No highscore", Color.Orange);
            }
            Cons.Write("   ");
            Cons.ReadKey();
            Cons.Clear();
            MainMenu();
        }