コード例 #1
0
        static void Main(string[] args)
        {
            Garage BriansGarage = new Garage();

            string userInput;

            Console.WriteLine("Select 1 to add a new car to your garage");
            Console.WriteLine("Select 2 to remove a car from your garage");
            Console.WriteLine("Select 3 to view all cars in your garage");
            Console.WriteLine("Select 4 to test drive a car");
            Console.WriteLine("Select 5 to refuel all the cars in your garage");
            userInput = Console.ReadLine();

            switch (userInput)
            {
            case "1":
                BriansGarage.AddCar();
                break;

            case "2":
                BriansGarage.RemoveCar();
                break;

            //case "3":
            //    BriansGarage.RemoveCar.
            //        break;
            //case "4":
            //    BriansGarage.myGarage.
            case "5":
                BriansGarage.FuelAllCars();
                break;
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            Garage garage = new Garage();

            garage.TitleScreen();

            bool flag = true;

            while (flag)
            {
                Console.Clear();
                garage.GarageScreen();
                Console.WriteLine("1.Choose a car to drive\n2.Refuel all cars\n3.Add a car\n4.Remove a car\n5.List all cars\n0.Exit");
                string input = Console.ReadLine();
                switch (input)
                {
                case "1":
                    garage.ListAllCars();
                    Console.WriteLine("Type ID to select car");
                    int id = Convert.ToInt32(Console.ReadLine());
                    SubMenu(garage.Select_Car(id));
                    break;

                case "2":
                    garage.FuelAllCars();
                    Console.WriteLine("All cars are fueled up and ready to go!");
                    Console.ReadKey();
                    break;

                case "3":
                    garage.AddNewCar("{0}", "{1}", 0, 100);
                    break;

                case "4":
                    garage.RemoveCar();
                    break;

                case "5":
                    garage.ListAllCars();
                    Console.ReadKey();
                    break;

                case "0":
                    flag = false;
                    break;

                default:
                    Console.WriteLine("Something went wrong.");
                    break;
                }
            }
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: MaryMcGeary/CarGarage
        static void Main(string[] args)
        {
            var garage = new Garage();

            Console.WriteLine("1. Add a car to the garage.");
            Console.WriteLine("2. Remove a car from the garage.");
            Console.WriteLine("3. List all cars.");
            Console.WriteLine("4. Test drive a car.");
            Console.WriteLine("5. Refuel all cars.");

            string menuChoice = Console.ReadLine();

            switch (menuChoice)
            {
            case "1":
                Console.WriteLine("What is the Make of your car?");
                var make = Console.ReadLine();
                Console.WriteLine("What is the Model of your car?");
                var model = Console.ReadLine();
                garage.AddCar(make, model);
                break;

            case "2":
                int carNum = Convert.ToInt32(Console.ReadLine());
                garage.RemoveCar(carNum);     //make this in garage as new method
                break;

            case "3":
                garage.ListAllCars();
                break;

            case "4":       //garage.TestDriveCar(); //make this in garage as new method
                Console.WriteLine("1. Turn on car");
                Console.WriteLine("2. Accelerate");
                Console.WriteLine("3. Brake");
                Console.WriteLine("4. Turn off car");
                Console.WriteLine("5. Return car");
                break;

            case "5":
                garage.FuelAllCars();
                break;

            default:
                Console.WriteLine("That wasn't an option! Try again.");
                break;
            }
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: khanishvili/CarGarage
        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);
        }
コード例 #5
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);
        }
コード例 #6
0
        //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);
        }