static void MainMenu() { Garage myParkingGarage = new Garage(); bool run = true; do { Console.Clear(); Console.WriteLine("Main Menu:"); Console.WriteLine("Press 1 to add a car"); if (myParkingGarage.ListOfCars.Count > 0) { Console.WriteLine("Press 2 to display cars' information"); Console.WriteLine("Press 3 to display cars' stats"); Console.WriteLine("Press 4 to do something with a vehicle"); Console.WriteLine("Press 5 to remove a car"); } Console.WriteLine("Press 0 to Quit"); ConsoleKeyInfo keyPressed = Console.ReadKey(); string menuChoice; if (char.IsDigit(keyPressed.KeyChar)) { menuChoice = keyPressed.KeyChar.ToString(); } else { menuChoice = "default"; } if (!menuChoice.Equals("1") && !menuChoice.Equals("0") && myParkingGarage.ListOfCars.Count == 0) { menuChoice = "-1"; } switch (menuChoice) { case "0": Console.WriteLine("\nSee you later alligator"); run = false; break; case "1": Console.WriteLine("\nAdd Car: "); myParkingGarage.AddNewCar(); break; case "2": myParkingGarage.DisplayCarInfo(); break; case "3": myParkingGarage.DisplayCarStats(); break; case "4": myParkingGarage.InteractionMenu(); break; case "5": myParkingGarage.RemoveCar(myParkingGarage.CarSelectionMenu()); break; default: Console.WriteLine("Please follow the instructions"); Console.WriteLine("Press any key to continue"); Console.ReadKey(); break; } } while (run); }
static void Main(string[] args) { Console.WriteLine("\t\t\t==== Wellcome ===="); Garage mycars = new Garage(); mycars.AddCar("Chevrolet", "Silverado"); mycars.AddCar("Audi", "Q7"); mycars.AddCar("Ford", "Fusion"); Console.WriteLine(mycars.MyCars.Count.ToString()); bool run = true; Header(); do { var key = Console.ReadKey(); switch (key.KeyChar) { case (char)ConsoleKey.D1: //Print Cars Console.WriteLine("press 0 to quit"); mycars.PrintCars(); break; case (char)ConsoleKey.D2: //Select car Console.WriteLine("Please Type ID (NUMBERS) only and Press Enter : "); int selector = Convert.ToInt32(Console.ReadLine()); if (selector > mycars.MyCars.Count) { Console.WriteLine("We don't have a car with this ID number"); } else { Test_Drive(mycars.SelectCar(selector)); } break; case (char)ConsoleKey.D3: //Add car Console.Write(" Make : "); string make = Console.ReadLine(); Console.Write(" Model : "); string model = Console.ReadLine(); mycars.AddCar(make, model); Console.WriteLine("Car {0} {1} is parked in garage", make, model); break; case (char)ConsoleKey.D4: //Remove Car Console.WriteLine("Please Type ID and Press Enter to remove car from list "); int index = Convert.ToInt32(Console.ReadLine()); mycars.RemoveCar(index); Console.WriteLine("Press 1 to Print list"); break; case (char)ConsoleKey.D5: //Fuell All Cars Console.WriteLine("You fueled all cars!"); mycars.FuelAllCars(); Console.WriteLine("press 0 to quit"); break; case (char)ConsoleKey.D0: //Select car run = false; break; default: Console.WriteLine("\n\npress 0 to quit"); break; } }while (run); }
static void Main(string[] args) { Garage myGarage = Intro(); Menu(myGarage); }
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); }
//It is very open to your interpretation, but it could look something like below, which basically gives the user the ability to interact with all the methods you created-> //A example Main menu to interact with the garage: //1. Add a Car to the Garage //2. Remove a Car from the Garage //3. List all Cars //4. Test drive a car //5. Refuel all cars //And then a sub menu to interact with the car that was selected(under 4. Test drive a car): //1. Turn on car //2. Accelerate //3. Brake //4. Turn off car //5. Return car static void Main(string[] args) { Garage joeGarage = new Garage(); int selection = 0; restartMainMenu(); do { var input = Console.ReadKey(false).Key; switch (input) { case ConsoleKey.D1: //the D1 means "1" above the q key and Numpad1 means "1" on num pad! case ConsoleKey.NumPad1: //once you're in the switch, it continues until a break, so D1 or NumPad1 //Console.WriteLine("Decision Has Been Made!!! - 1\n"); selection = 1; Console.WriteLine("Add a Car to the Garage!\n"); Console.Write("\tEnter Make: "); string theMake = Console.ReadLine(); Console.Write("\n\tEnter Model: "); string theModel = Console.ReadLine(); joeGarage.AddCar(theMake, theModel); restartMainMenu(); break; case ConsoleKey.D2: case ConsoleKey.NumPad2: //Console.WriteLine("Decision Has Been Made!!! - 2\n"); selection = 2; Console.WriteLine("Remove a Car from the Garage!\n"); Console.Write("\tEnter Make: "); string theRemovedMake = Console.ReadLine(); Console.Write("\n\tEnter Model: "); string theRemovedModel = Console.ReadLine(); joeGarage.RemoveCarByMakeAndModel(theRemovedMake, theRemovedModel); Console.WriteLine("\n...Press Enter to Continue"); Console.ReadLine(); restartMainMenu(); break; case ConsoleKey.D3: case ConsoleKey.NumPad3: //Console.WriteLine("Decision Has Been Made!!! - 3\n"); selection = 3; Console.WriteLine(" MAKE MODEL RUNNING? FUEL SPEED"); for (int car = 0; car < joeGarage.TheGarage.Count; car++) { Console.WriteLine(car + " " + joeGarage.AllStatsofCarToString(car)); } Console.WriteLine("\n...Press Enter to Continue"); Console.ReadLine(); restartMainMenu(); break; case ConsoleKey.D4: case ConsoleKey.NumPad4: //Console.WriteLine("Decision Has Been Made!!! - 4\n"); selection = 4; carOpsMenu(ref joeGarage); selection = 0; restartMainMenu(); break; case ConsoleKey.D5: case ConsoleKey.NumPad5: Console.WriteLine("Decision Has Been Made!!! - 5\n"); selection = 5; joeGarage.FuelAllCars(); Console.WriteLine("\n...Press Enter to Continue"); Console.ReadLine(); restartMainMenu(); break; case ConsoleKey.Escape: selection = 6; break; case ConsoleKey.Enter: break; default: break; } } while (selection != 6); }
public static void carOpsMenu(ref Garage g) { int selection = -1; int carChoice = -1; if (g.TheGarage.Count > 0) { do { Console.Clear(); Console.WriteLine("----- TEST DRIVE -----"); Console.WriteLine(" MAKE MODEL RUNNING? FUEL SPEED"); for (int car = 0; car < g.TheGarage.Count; car++) { Console.WriteLine(car + " " + g.AllStatsofCarToString(car)); } Console.Write("\n\tSelect a Car# and Press Enter :"); carChoice = Convert.ToInt32(Console.ReadLine()); } while ((!(carChoice > 0)) && (!(carChoice < g.TheGarage.Count))); do { Console.Clear(); Console.WriteLine("Test Driving the " + g.TheGarage[carChoice].GetMake() + ", " + g.TheGarage[carChoice].GetModel() + "\n"); Console.WriteLine("1. Turn Engine On"); Console.WriteLine("2. Accelerate"); Console.WriteLine("3. Brake"); Console.WriteLine("4. Turn Off"); Console.WriteLine("5. Return"); Console.WriteLine("....Choose an option: "); var input = Console.ReadKey(false).Key; switch (input) { case ConsoleKey.D1: //the D1 means "1" above the q key and Numpad1 means "1" on num pad! case ConsoleKey.NumPad1: //once you're in the switch, it continues until a break, so D1 or NumPad1 selection = 1; Console.WriteLine("...Turn on the Engine!\n"); if (g.TheGarage[carChoice].IsStarted()) { Console.WriteLine("!!! It's already running"); } else { g.TheGarage[carChoice].ToggleEngine(); Console.WriteLine("Car is Running Now!"); } Console.WriteLine("\n...Press Enter to Continue"); Console.ReadLine(); break; case ConsoleKey.D2: case ConsoleKey.NumPad2: selection = 2; Console.WriteLine("...Accelerate!\n"); if (g.TheGarage[carChoice].IsStarted()) { g.TheGarage[carChoice].Accelerate(); Console.WriteLine(" Yep, you've accelerated!"); Console.WriteLine(" Current Speed is " + g.TheGarage[carChoice].GetSpeed() + " mph."); } else { Console.WriteLine("!!! Can't Accelerate, Car is NOT Running Now!"); } Console.WriteLine("\n...Press Enter to Continue"); Console.ReadLine(); break; case ConsoleKey.D3: case ConsoleKey.NumPad3: Console.WriteLine("...\n"); selection = 3; Console.WriteLine("...Brake!\n"); int currentSpeed = g.TheGarage[carChoice].GetSpeed(); if (currentSpeed > 0) { g.TheGarage[carChoice].Brake(); Console.WriteLine(" Yep, you've braked! Going Slower"); Console.WriteLine(" Current Speed is " + g.TheGarage[carChoice].GetSpeed() + " mph."); } else { Console.WriteLine("!!! No need to break, Car is NOT moving Now!"); } Console.WriteLine("\n...Press Enter to Continue"); Console.ReadLine(); break; case ConsoleKey.D4: case ConsoleKey.NumPad4: selection = 4; Console.WriteLine("...Turn Off Engine!\n"); int speed = g.TheGarage[carChoice].GetSpeed(); bool on = g.TheGarage[carChoice].IsStarted(); if (speed > 0) { Console.WriteLine("!!! Can't turn engine off, need to BRAKE " + (speed / 10) + " times first."); } else if (!on) { Console.WriteLine("!!! Can't turn engine off, Car is already NOT Running Now!"); } else { g.TheGarage[carChoice].ToggleEngine(); Console.WriteLine("Yep, you've turned off engine"); } Console.WriteLine("\n...Press Enter to Continue"); Console.ReadLine(); break; case ConsoleKey.D5: case ConsoleKey.NumPad5: selection = 5; break; case ConsoleKey.Escape: selection = 5; break; case ConsoleKey.Enter: break; default: break; } } while (selection != 5); } else { Console.WriteLine("No Cars!"); Console.WriteLine("Add some Cars, first - press enter to continue"); Console.ReadLine(); } return; }