示例#1
0
        static void Main(string[] args)
        {
            //Create new Games List
            Game        g  = new Game();
            ListEmpty   le = new ListEmpty();
            GameList    gl = new GameList(g, le);
            List <Game> Games;

            Games = gl.CreateGameList();

            int input = 1;

            while (input != 0)
            {
                Console.WriteLine("Sort your Games by Sell Price!");
                Console.WriteLine("----------------");
                Console.WriteLine();
                Console.WriteLine("Choose from the following options:");
                Console.WriteLine("  1: Add a game");
                Console.WriteLine("  2: View random 10 Games (unsorted) from list");
                Console.WriteLine("  3: View current (unsorted) list");
                Console.WriteLine("  4: View the Current Games List - Ascending Order");
                Console.WriteLine("  5: View the Current Games List - Descending Order");
                Console.WriteLine("  6: Clear your current Games List");
                Console.WriteLine("  7: Create a new Games List");
                Console.WriteLine("  0: Exit application");
                Console.WriteLine("----------------");
                string inp   = Console.ReadLine();
                int    outc  = 6;
                bool   check = Int32.TryParse(inp, out outc);
                if (check)
                {
                    input = Int32.Parse(inp);
                }
                else
                {
                    input = 6;  //hard coded, not sure why it sets to 0 atm
                }
                MergeSortAlgorithm ms           = new MergeSortAlgorithm(le);
                List <Game>        newGamesList = ms.MergeSort(Games);

                switch (input)
                {
                case 1:
                {
                    int    price;
                    string nameGame;
                    Console.WriteLine("You MAY enter a price for your game, then hit return:");
                    var  p       = Console.ReadLine();
                    int  result  = 0;
                    bool outcome = int.TryParse(p, out result);
                    if (outcome)
                    {
                        price = Int32.Parse(p);
                    }
                    else
                    {
                        price = result;
                    }
                    Console.WriteLine("You MAY enter a name of a game, then hit return:");
                    nameGame = Console.ReadLine();
                    g.AddNewGame(price, nameGame);
                    Games = gl.ReturnGames();
                    break;
                }

                case 2:
                {
                    Console.WriteLine("10 games in your list include:");
                    ms.Print10(g, gl);
                    Console.WriteLine("----------------");
                    break;
                }

                case 3:
                {
                    Console.WriteLine("The current list of {0} games in it's unsorted order", Games.Count);
                    ms.PrintAll(Games, false);
                    Console.WriteLine("----------------");
                    break;
                }

                case 4:
                {
                    Console.WriteLine("Now we'll sort the list of {0} games with MergeSort in ascending order", newGamesList.Count);
                    ms.PrintAll(newGamesList, false);
                    Console.WriteLine("----------------");
                    break;
                }

                case 5:
                {
                    Console.WriteLine("Now we'll sort the list of {0} games with MergeSort in descending order", newGamesList.Count);
                    ms.PrintAll(newGamesList, true);
                    Console.WriteLine("----------------");
                    break;
                }

                case 6:
                {
                    Console.WriteLine("Are you sure you want to clear your Game List? - Press Y to confirm");
                    string answer = Console.ReadLine();
                    if (answer == "Y" || answer == "y")
                    {
                        gl.ClearList();
                    }
                    break;
                }

                case 7:
                {
                    gl.CreateGameList();
                    break;
                }

                default:
                {
                    Console.WriteLine("You didn't enter in a correct value");
                    break;
                }
                }
            }
            Console.WriteLine("-------------------");
            Console.WriteLine("End of the Application");
        }