コード例 #1
0
        /// <summary>
        /// get the menu choice from the user
        /// </summary>
        public MenuOption DisplayGetUserMenuChoice()
        {
            MenuOption userMenuChoice = MenuOption.None;
            bool       usingMenu      = true;

            while (usingMenu)
            {
                // set up display area
                ConsoleUtil.DisplayReset();
                Console.CursorVisible = false;
                // display the menu
                ConsoleUtil.DisplayMessage("Please type the number of your menu choice.");
                Console.WriteLine();
                Console.WriteLine(
                    "\t" + "1. Travel" + Environment.NewLine +
                    "\t" + "2. Buy" + Environment.NewLine +
                    "\t" + "3. Sell" + Environment.NewLine +
                    "\t" + "4. Display Inventory" + Environment.NewLine +
                    "\t" + "5. Display Cities" + Environment.NewLine +
                    "\t" + "6. Display Account Info" + Environment.NewLine +
                    "\t" + "7. Look Into The Future" + Environment.NewLine +
                    "\t" + "8. Travel Back In Time" + Environment.NewLine +
                    "\t" + "E. Exit" + Environment.NewLine);
                // get and process the user's response
                // note: ReadKey argument set to "true" disables the echoing of the key press
                ConsoleKeyInfo userResponse = Console.ReadKey(true);
                switch (userResponse.KeyChar)
                {
                case '1':
                    userMenuChoice = MenuOption.Travel;
                    usingMenu      = false;
                    break;

                case '2':
                    userMenuChoice = MenuOption.Buy;
                    usingMenu      = false;
                    break;

                case '3':
                    userMenuChoice = MenuOption.Sell;
                    usingMenu      = false;
                    break;

                case '4':
                    userMenuChoice = MenuOption.DisplayInventory;
                    usingMenu      = false;
                    break;

                case '5':
                    userMenuChoice = MenuOption.DisplayCities;
                    usingMenu      = false;
                    break;

                case '6':
                    userMenuChoice = MenuOption.DisplayAccountInfo;
                    usingMenu      = false;
                    break;

                case '7':
                    userMenuChoice = MenuOption.LookIntoTheFuture;
                    usingMenu      = false;
                    break;

                case '8':
                    userMenuChoice = MenuOption.TravelBackInTime;
                    usingMenu      = false;
                    break;

                case 'E':
                case 'e':
                    userMenuChoice = MenuOption.Exit;
                    usingMenu      = false;
                    break;

                default:
                    break;
                }
            }
            Console.CursorVisible = true;

            return(userMenuChoice);
        }