Exemplo n.º 1
0
 private void TESTING()
 {
     if (valet.GarageExist)
     {
         valet.RazeGarage();
     }
     valet.BuildGarage(15);
     valet.Park(new Boat("boat1", "0", "13", "55"));
     valet.Park(new Car("car1", "4", "Gas", CarTypes.Sport.ToString()));
     valet.Park(new Airplane("ap1", "3", "Kerosene", "250"));
     valet.Park(new Car("car2", "5", "Disel", CarTypes.Family.ToString()));
     valet.Park(new Car("car3", "4", "Gas", CarTypes.Sport.ToString()));
     valet.Park(new Bus("bus1", "6", "Biodisel", "40"));
     valet.Park(new Motorcycle("bike1", "2", "HD", "Black"));
     valet.Park(new Motorcycle("bike2", "3", "Kawasaki 125", "Pink"));
     valet.Park(new Boat("boat2", "0", "5", "600"));
     valet.Park(new Airplane("ap2", "3", "Crude oil", "4"));
     valet.Park(new Car("car4", "4", "Gas", CarTypes.Family.ToString()));
     valet.Park(new Car("car5", "4", "Ethanol", CarTypes.Family.ToString()));
     valet.Park(new Car("car6", "4", "Disel", CarTypes.Family.ToString()));
     Console.Clear();
     Console.WriteLine("Cheater!!!");
     Console.WriteLine();
 }
Exemplo n.º 2
0
        /// <summary>
        /// Hanterar navigation i garagevyn. ShowGarage kallar vidare på DrawLayout, VehicleInfo, ShowSearchResult och Search
        /// </summary>
        /// <param name="name"></param>
        static void ShowGarage(string name)
        {
            Console.Clear();
            //pos: Vilken parkering som är fokuserad
            int pos = 1;
            //Antal parkeringsplatser
            int l = gh.GetParkingspots().Length;

            while (true)
            {
                Console.SetCursorPosition(0, 0);
                Console.WriteLine(name);
                Console.WriteLine("Parked vehicles:");
                ClearLine();
                //Anpassar indraget efter hur många parkeringar som existerar
                int left = Console.CursorLeft + l * 4;
                int top  = Console.CursorTop;
                if (left > Console.WindowWidth / 2)
                {
                    left = 1;
                }
                ClearLine();
                //Skriver ut sökresultaten
                ShowSearchResult(gh.searchQuery);
                //Rita ut Layouten på garaget
                DrawLayout(pos);
                //Skriv ut info om fokuserad parkering
                VehicleInfo(pos);

                //Navigation
                ConsoleKeyInfo keyInfo = Console.ReadKey();
                if (keyInfo.Key == ConsoleKey.UpArrow || keyInfo.Key == ConsoleKey.DownArrow) // Navigera upp/ned
                {
                    if (pos >= 1 && pos <= l / 2)
                    {
                        pos += l / 2;
                    }
                    else if (pos >= l / 2 && pos <= l)
                    {
                        pos -= l / 2;
                    }
                }
                else if (keyInfo.Key == ConsoleKey.LeftArrow) //Navigera vänster
                {
                    if (pos > 1 && pos <= l / 2 || pos > (l / 2) + 1 && pos <= l)
                    {
                        pos--;
                    }
                    else if (pos == 1)
                    {
                        pos = l / 2;
                    }
                    else if (pos == (l / 2) + 1)
                    {
                        pos = l;
                    }
                }
                else if (keyInfo.Key == ConsoleKey.RightArrow) //Navigera höger
                {
                    if (pos >= 1 && pos < l / 2 || pos > l / 2 && pos < l)
                    {
                        pos++;
                    }
                    else if (pos == l / 2)
                    {
                        pos = 1;
                    }
                    else if (pos == l)
                    {
                        pos = (l / 2) + 1;
                    }
                }
                else if (keyInfo.Key == ConsoleKey.Escape) //Backa
                {
                    return;
                }
                else if (keyInfo.Key == ConsoleKey.Enter) //Interagera
                {
                    //Kör användaren ett fordon?
                    if (gh.SelectedVehicle != null)
                    {
                        //Är vald parkering tom?
                        if (gh.GetVehicle(pos) == null)
                        {
                            Console.WriteLine("Park your vehicle in spot #{0}? (Y/N)", pos);
                            //Kolla om användaren vill parkera
                            if (Console.ReadLine()[0].ToString().ToUpper() == "Y")
                            {
                                //Parkera fordonet
                                gh.Park(pos, gh.SelectedVehicle);
                                //Nollställ användarens fordon
                                gh.SelectedVehicle = null;
                            }
                            //Börja om loopen
                            continue;
                        }
                        else
                        {
                            Console.WriteLine("You need to park your current vehicle before leaving with another!");
                        }
                    }
                    //Kör användaren ej?
                    else if (gh.SelectedVehicle == null)
                    {
                        //Innehåller fokuserad parkering ett fordon?
                        if (gh.GetVehicle(pos) != null)
                        {
                            Console.WriteLine("Do you want to take the {0} for a drive? (Y/N)", gh.GetVehicle(pos).Name);
                            //Vill användaren köra fordonet?
                            if (Console.ReadLine()[0].ToString().ToUpper() == "Y")
                            {
                                gh.SelectedVehicle = gh.Unpark(pos); //Backa ut från parkeringen
                            }
                            continue;                                //Börja om loopen
                        }
                        else
                        {
                            Console.WriteLine("You need a vehicle before you can park!");
                        }
                    }
                    Console.ReadKey();
                }
                else if (keyInfo.Key == ConsoleKey.Backspace || char.IsLetter(keyInfo.KeyChar)) //Updatera sökfras
                {
                    gh.Search(keyInfo);
                }
            }
        }
Exemplo n.º 3
0
        public void UserInterface()
        {
            // string regno;
            //string type;
            while (true)
            {
                Console.WriteLine("--------------------------------");
                Console.WriteLine("Press 1 to Park A New Vehicle");
                Console.WriteLine("Press 2 to UnPark A New Vehicle");
                Console.WriteLine("Press 3 to show A list of all vehicles");
                Console.WriteLine("Press 4 to A find a certian vehicle");
                Console.WriteLine("Press 5 to A show all vehicles with 4 Wheels");
                Console.WriteLine("Press q To Quit");

                char input = ' ';
                try
                {
                    input = Console.ReadLine()[0];
                }
                catch (IndexOutOfRangeException)
                {
                    Console.Clear();
                    Console.WriteLine("Please Enter A Valid Value");
                }

                switch (input)
                {
                case '1':
                    //Call Add Method

                    GH.Park();

                    break;

                case '2':
                    // Call Remove Method
                    Console.WriteLine("Please Enter A regNr to delet a Vehicle");
                    string regno = Console.ReadLine();
                    //  GH.UnPark(regno);

                    string Rmsg = GH.UnPark(regno);
                    Console.WriteLine(Rmsg);


                    break;

                case '3':
                    //Call Stats Method

                    GH.ListOfAllVehicle();
                    break;

                case '4':
                    Console.WriteLine("Please Enter A regNr to find a Vehicle");
                    string regno1 = Console.ReadLine();
                    GH.FindAVehicle(regno1);
                    string feedback = GH.FindAVehicle(regno1);
                    Console.WriteLine(feedback);
                    break;

                case '5':
                    Console.WriteLine("---------------");
                    // GH.Findall4WheelVehicle();
                    string feedback1 = GH.Findall4WheelVehicle();
                    Console.WriteLine(feedback1);
                    break;

                case 'q':
                    Environment.Exit(0);
                    break;

                default:
                    Console.WriteLine("Please Enter A valid choice");
                    UserInterface();
                    break;
                }
            }
        }