Ejemplo n.º 1
0
 public ScoreIterator(ScoreAggregate aggregate)
 {
     this.aggregate = aggregate;
     current        = 0;
 }
Ejemplo n.º 2
0
        public static void ScoreboardMenu()
        {
            Console.Clear();
            ConsoleKeyInfo keyInfo;

            GameData.DrawText();
            string line;

            string[] data       = new string[3];
            int      pageNumber = 1;
            Score    score;

            Console.SetCursorPosition(55, 15);
            Console.Write("Name: ");
            Console.Write("Score: ");
            Console.Write("Difficulty: ");

            Console.SetCursorPosition(47, 40);
            Console.Write("Previous page: <-      ");
            Console.Write("Next page: ->");
            Console.SetCursorPosition(62, 42);
            Console.Write("Page " + pageNumber);
            Console.SetCursorPosition(53, 45);
            Console.Write("ESC - BACK TO MAIN MENU");

            int x = 55, y = 17;

            ScoreAggregate scoreAggregate = new ScoreAggregate();

            try
            {
                StreamReader file = new StreamReader(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\ranking.txt");

                while ((line = file.ReadLine()) != null)
                {
                    data  = line.Split(' ');
                    score = new Score(data[0], data[1], data[2]);
                    scoreAggregate.AddScore(score);
                }
                file.Close();

                IPageIterator scoreIterator = scoreAggregate.CreateIterator();

                Console.SetCursorPosition(x, y);
                foreach (Score s in ((IEnumerable <Score>)scoreIterator.GetPage()))
                {
                    Console.Write(s);
                    y += 2;
                    Console.SetCursorPosition(x, y);
                }

                do
                {
                    keyInfo = Console.ReadKey(true);
                    y       = 17;
                    switch (keyInfo.Key)
                    {
                    case ConsoleKey.RightArrow:
                        if (scoreIterator.HasNextPage())
                        {
                            pageNumber += 1;
                            GameData.ClearText(new Position(0, 17), new Position(130, 39));
                            scoreIterator.NextPage();
                            Console.SetCursorPosition(x, y);
                            foreach (Score s in ((IEnumerable <Score>)scoreIterator.GetPage()))
                            {
                                Console.Write(s);
                                y += 2;
                                Console.SetCursorPosition(x, y);
                            }
                            Console.SetCursorPosition(67, 42);
                            Console.Write(pageNumber);
                        }
                        break;

                    case ConsoleKey.LeftArrow:
                        if (scoreIterator.HasPreviousPage())
                        {
                            pageNumber -= 1;
                            GameData.ClearText(new Position(0, 17), new Position(130, 39));
                            scoreIterator.PreviousPage();
                            Console.SetCursorPosition(x, y);
                            foreach (Score s in ((IEnumerable <Score>)scoreIterator.GetPage()))
                            {
                                Console.Write(s);
                                y += 2;
                                Console.SetCursorPosition(x, y);
                            }
                            Console.SetCursorPosition(67, 42);
                            Console.Write("         ");
                            Console.SetCursorPosition(67, 42);
                            Console.Write(pageNumber);
                        }
                        break;
                    }
                } while (keyInfo.Key != ConsoleKey.Escape);
            }
            catch (FileNotFoundException) { }
        }