Esempio n. 1
0
        public static void HandleParkers(Queue <Parker> parkers)
        {
            PrintQueue(parkers);
            int parkerCount = parkers.Count;

            Console.CursorTop = 4;
            while (parkers.Count > 0)
            {
                var parker     = parkers.Dequeue();
                var parkerType = parker.IsContractor ? "Contractor" : "Employee";

                Console.WriteLine($"\nWould you like to park in the surface lot or parking garage?");
                Console.Write("Enter s or g:");
                bool validResponse = false;

                IParkingLot parkingLot = null;

                while (!validResponse)
                {
                    var enteredText = Console.ReadLine().Trim().ToLower();
                    if (!String.Equals(enteredText, "s", StringComparison.OrdinalIgnoreCase) &&
                        !String.Equals(enteredText, "g", StringComparison.OrdinalIgnoreCase))
                    {
                        var currentPosition = Console.CursorTop;
                        RefreshConsole(parkers);
                        Console.SetCursorPosition(0, 7);
                        Console.Write("Invalid input. Please enter s or g:");
                    }
                    else
                    {
                        validResponse = true;

                        if (String.Equals(enteredText, "g", StringComparison.OrdinalIgnoreCase))
                        {
                            parkingLot = new ParkingGarage(parker);
                        }
                        else
                        {
                            parkingLot = new SurfaceLot();
                        }
                    }
                }

                parkingLot?.Park();

                parkerCount--;

                Console.WriteLine("\nPress any key to continue...");
                Console.ReadKey();

                RefreshConsole(parkers);
                Console.CursorTop = 4;
            }
        }
Esempio n. 2
0
 public ParkingGarage(Parker parker)
 {
     _parker     = parker;
     _surfaceLot = new SurfaceLot();
 }