Ejemplo n.º 1
0
        static void Menu(Garage myGarage)
        {
            Car  selectedCar      = new Car();
            int  selectedCarIndex = -1;
            bool run = true;

            do
            {
                Pause();

                string menuTitle = "Main Menu | " + myGarage.UserName + "'s Garage | ";
                if (myGarage.IsCarCheckedOut)
                {
                    menuTitle += "Current Car: " + selectedCar.Year + " " + selectedCar.Make + " " + selectedCar.Model;
                }
                else
                {
                    menuTitle += "No Car Selected";
                }

                List <string> menuItems = new List <string>()
                {
                    menuTitle,
                    "1. Add Cars"
                };

                int menuIndex = 2;

                if (myGarage.ParkingSpots.Count > 0)
                {
                    menuItems.Add(menuIndex + ". Remove Car");
                    menuIndex++;

                    if (myGarage.IsCarCheckedOut)
                    {
                        menuItems.Add(menuIndex + ". Return Car");
                        menuIndex++;
                    }
                    else
                    {
                        menuItems.Add(menuIndex + ". Drive Car");
                        menuIndex++;
                    }
                    menuItems.Add(menuIndex + ". Refuel All Cars");
                    menuIndex++;
                }
                menuItems.Add(menuIndex + ". Quit");

                foreach (string item in menuItems)
                {
                    Console.WriteLine(item);
                }

                ConsoleKeyInfo itemChosen = Console.ReadKey();
                Console.WriteLine("");

                int indexCheck = menuItems.Count + 1;
                switch (itemChosen.Key)
                {
                case (ConsoleKey.D1):
                case ConsoleKey.NumPad1:
                    indexCheck = 1;
                    break;

                case ConsoleKey.D2:
                case ConsoleKey.NumPad2:
                    indexCheck = 2;
                    break;

                case ConsoleKey.D3:
                case ConsoleKey.NumPad3:
                    indexCheck = 3;
                    break;

                case ConsoleKey.D4:
                case ConsoleKey.NumPad4:
                    indexCheck = 4;
                    break;

                case ConsoleKey.D5:
                case ConsoleKey.NumPad5:
                    indexCheck = 5;
                    break;

                default:
                    break;
                }

                string itemSelected = "";
                if (indexCheck < menuItems.Count)
                {
                    itemSelected = menuItems[indexCheck].Substring(3).Remove(3);
                }

                switch (itemSelected)
                {
                case "Add":
                    myGarage = UserAddsCar(myGarage);
                    break;

                case "Rem":
                    myGarage = UserRemovesCar(myGarage);
                    break;

                case "Ret":
                    myGarage.ReturnCar(selectedCarIndex, selectedCar);
                    break;

                case "Dri":
                    selectedCarIndex = SelectCar(myGarage);
                    selectedCar      = DriveCarMenu(myGarage.CheckoutCar(selectedCarIndex));
                    break;

                case "Ref":
                    myGarage.FuelAllCars();
                    break;

                case "Qui":
                    Console.WriteLine("Thank you for playing, CarGarage! See you next time!");
                    return;

                default:
                    TryAgain();
                    break;
                }
            } while (run);
        }