Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Highscores     m_sys = Highscores.ScoreReader();
            ConsoleKeyInfo i;

            do
            {
                Console.Clear();
                Console.WriteLine("1. new game");
                Console.WriteLine("2. highscores");
                i = Console.ReadKey();
                switch (i.KeyChar)
                {
                case '1':
                    Game(m_sys);
                    break;

                case '2':
                    Highscore(m_sys);
                    break;

                default:
                    break;
                }
            } while (i.Key != ConsoleKey.Escape);
        }
Ejemplo n.º 2
0
        public static Highscores ScoreReader()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(Highscores));
            StreamReader  reader     = new StreamReader(m_path);
            Highscores    m_sys      = (Highscores)serializer.Deserialize(reader);

            reader.Close();
            return(m_sys);
        }
Ejemplo n.º 3
0
        static void Highscore(Highscores sys)
        {
            IEnumerable <Score> query = sys.Scores.OrderBy(order => order.Points).Reverse();

            Console.Clear();

            foreach (Score i in query)
            {
                Console.WriteLine("{0} - {1}", i.Points, i.Name);
            }

            Console.ReadKey();
        }
Ejemplo n.º 4
0
        static void Game(Highscores sys)
        {
            Console.Clear();
            int points = 0;
            int tries  = 3;


            while (NewGame(tries, out int newTries))
            {
                points++;
                tries = newTries;
            }
            EndGame(points, sys);
        }
Ejemplo n.º 5
0
        static void EndGame(int points, Highscores sys)
        {
            Console.Clear();
            Console.WriteLine("game over");
            Console.WriteLine("Please input name");
            string name = Console.ReadLine();

            Score score = new Score
            {
                Name   = name,
                Points = points.ToString()
            };

            sys.Scores.Add(score);
            sys.Save();

            Highscore(sys);
        }