Пример #1
0
        public void Run()
        {
            string             input;
            IComparer <Player> sorterAlpha       = new CompareByName(true);
            IComparer <Player> sorterContraAlpha = new CompareByName(false);

            do
            {
                Console.WriteLine("Menu");
                Console.WriteLine("----");
                Console.WriteLine("1. Insert Player");
                Console.WriteLine("2. List all players");
                Console.WriteLine("3. List players with score greater than");
                Console.WriteLine("4. Sort by score");
                Console.WriteLine("5. Sort by name");
                Console.WriteLine("6. Sort by name (inverted)");
                Console.WriteLine("E. Exit");
                Console.WriteLine();
                Console.Write("> ");
                input = Console.ReadLine().ToUpper();
                switch (input)
                {
                case "1":
                    InsertPlayer();
                    break;

                case "2":
                    ShowPlayers(playerList);
                    break;

                case "3":
                    ShowPlayersWithScore();
                    break;

                case "4":
                    playerList.Sort();
                    Console.WriteLine("List sorted by score");
                    break;

                case "5":
                    playerList.Sort(sorterAlpha);
                    Console.WriteLine("List sorted by name");
                    break;

                case "6":
                    playerList.Sort(sorterContraAlpha);
                    Console.WriteLine("List sorted by name (inverse)");
                    break;

                case "E":
                    break;

                default:
                    Console.WriteLine("!!! Unknown option !!!");
                    break;
                }
                Console.WriteLine("Press any key to continue...");
                Console.ReadKey();
            }while (input != "E");
        }
Пример #2
0
        /// <summary>
        /// Start the player listing program instance
        /// </summary>
        private void Start()
        {
            // Declare variable of type Icomparer
            IComparer <Player> comp = new CompareByName(false);

            // We keep the user's option here
            string option;

            // Main program loop
            do
            {
                // Show menu and get user option
                ShowMenu();
                option = Console.ReadLine();

                // Determine the option specified by the user and act on it
                switch (option)
                {
                case "1":
                    InsertPlayer();
                    break;

                case "2":

                    playerList.Sort(comp);
                    ListPlayers(playerList);
                    break;

                case "3":
                    playerList.Sort(comp);
                    ListPlayersWithScoreGreaterThan();
                    break;

                case "4":
                    Console.WriteLine("Bye!");
                    break;

                default:
                    Console.Error.WriteLine("\n>>> Unknown option! <<<\n");
                    break;
                }

                // Wait for user to press a key...
                Console.Write("\nPress any key to continue...");
                Console.ReadKey(true);
                Console.WriteLine("\n");

                // Loop keeps going until players choses to quit (option 4)
            } while (option != "4");
        }
Пример #3
0
        private void Start()
        {
            // Variables
            string             choice;
            IComparer <Player> comp = new CompareByName(false);

            // Sort list by score
            players.Sort(comp);

            // Menu cicle
            do
            {
                // Show options
                Console.WriteLine("Menu  (Select option number)");
                Console.Write("Option 1:   Insert player.\n");
                Console.Write("Option 2:   List all players.\n");
                Console.Write("Option 3:   List players with greater score.\n");
                Console.Write("Option 4:   Exit.\n");

                // Save anwser

                choice = Console.ReadLine();

                // Verify anwser
                switch (choice)
                {
                case "1":
                    InsertPlayer();
                    players.Sort(comp);
                    break;

                case "2":
                    ListPlayers(players);
                    break;

                case "3":
                    ListGreaterThan();
                    break;

                case "4":
                    break;

                default:
                    Console.WriteLine("Invalid option");
                    break;
                }

                Console.Clear();
            } while (choice != "4");
        }