Esempio n. 1
0
        /// <summary>
        /// Main GUI builder. Prints most of the structure using stringbuilder
        /// </summary>
        /// <param name="lane1"></param>
        /// <param name="lane2"></param>
        /// <param name="lane3"></param>
        /// <param name="vehicleQueue"></param>
        /// <param name="carsLeft"></param>
        private static void LaneAndDetails(Lane lane1, Lane lane2, Lane lane3, List <Vehicle> vehicleQueue, int carsLeft, Counters counters, float totalLitresDispensed)
        {
            string whitespace = "   ";

            //Line 0
            GuiBuilder(true, 12, false);
            Console.Write("LANE ONE");
            GuiBuilder(false, 11, true);
            Console.Write(whitespace);
            GuiBuilder(true, 11, false);
            Console.Write("DETAILS");
            GuiBuilder(false, 10, true);
            Console.WriteLine();

            //Line 1
            PrintLanes(lane1, 1);
            Console.Write(whitespace);
            GuiBuilder(true, 0, false);
            Console.Write(whitespace);
            Console.Write("Jake"); //May eventually show logged in user.
            Console.SetCursorPosition(65, 1);
            GuiBuilder(true, 0, false);
            Console.WriteLine();

            //Line 2
            GuiBuilder(true, 12, false);
            Console.Write("LANE TWO");
            GuiBuilder(false, 11, true);
            Console.Write(whitespace);
            GuiBuilder(true, 0, false);
            Console.Write(whitespace);
            Console.Write("CARS WAITING:");
            Console.SetCursorPosition(59, 2);
            Console.Write(vehicleQueue.Count); //Will eventually show length of cars list
            Console.SetCursorPosition(65, 2);
            GuiBuilder(true, 0, false);
            Console.WriteLine();

            //Line 3
            PrintLanes(lane2, 4);
            Console.Write(whitespace);
            GuiBuilder(true, 0, false);
            Console.Write(whitespace);
            Console.Write("CARS SERVICED:");
            Console.SetCursorPosition(59, 3);
            Console.Write(counters.GetCarsServiced()); //Will eventually show number of cars serviced
            Console.SetCursorPosition(65, 3);
            GuiBuilder(true, 0, false);
            Console.WriteLine();

            //Line 4
            GuiBuilder(true, 11, false);
            Console.Write("LANE THREE");
            GuiBuilder(false, 10, true);
            Console.Write(whitespace);
            GuiBuilder(true, 0, false);
            Console.Write(whitespace);
            Console.Write("CARS LEFT:");
            Console.SetCursorPosition(59, 4);
            Console.Write(carsLeft);
            Console.SetCursorPosition(65, 4);
            GuiBuilder(true, 0, false);
            Console.WriteLine();


            //Line 5
            PrintLanes(lane3, 7);
            Console.Write(whitespace);
            GuiBuilder(true, 0, false);
            Console.Write(whitespace);
            Console.Write("Litres Dispensed:");
            Console.SetCursorPosition(59, 5);
            Console.Write(Math.Round(totalLitresDispensed, 2)); //Will eventually show number of cars serviced
            Console.SetCursorPosition(65, 5);
            GuiBuilder(true, 0, false);
            Console.WriteLine();

            //Line 6
            GuiBuilder(true, 31, true);
            Console.Write(whitespace);
            GuiBuilder(true, 28, true);
        }
        //Checks for key press, if one is selected, loads pump select method and reloads GUI
        private static bool CheckKeyPress(Lane lane1, Lane lane2, Lane lane3, List <Vehicle> vehicle, int fcarsLeft, Counters counters, float totalLitresDispensed, bool fProgramRun)
        {
            ConsoleKeyInfo keyPress = Console.ReadKey(true);

            //Lane 1
            if (keyPress.Key == ConsoleKey.D1 & vehicle.Count > 0 || keyPress.Key == ConsoleKey.NumPad1 & vehicle.Count > 0)
            {
                PumpSelect(0, lane1, vehicle);
                GUI.LoadGui(lane1, lane2, lane3, vehicle, fcarsLeft, counters, totalLitresDispensed);
            }

            if (keyPress.Key == ConsoleKey.D2 & vehicle.Count > 0 || keyPress.Key == ConsoleKey.NumPad2 & vehicle.Count > 0)
            {
                PumpSelect(1, lane1, vehicle);
                GUI.LoadGui(lane1, lane2, lane3, vehicle, fcarsLeft, counters, totalLitresDispensed);
            }

            if (keyPress.Key == ConsoleKey.D3 & vehicle.Count > 0 || keyPress.Key == ConsoleKey.NumPad3 & vehicle.Count > 0)
            {
                PumpSelect(2, lane1, vehicle);
                GUI.LoadGui(lane1, lane2, lane3, vehicle, fcarsLeft, counters, totalLitresDispensed);
            }

            //Lane 2
            if (keyPress.Key == ConsoleKey.D4 & vehicle.Count > 0 || keyPress.Key == ConsoleKey.NumPad4 & vehicle.Count > 0)
            {
                PumpSelect(0, lane2, vehicle);
                GUI.LoadGui(lane1, lane2, lane3, vehicle, fcarsLeft, counters, totalLitresDispensed);
            }

            if (keyPress.Key == ConsoleKey.D5 & vehicle.Count > 0 || keyPress.Key == ConsoleKey.NumPad5 & vehicle.Count > 0)
            {
                PumpSelect(1, lane2, vehicle);
                GUI.LoadGui(lane1, lane2, lane3, vehicle, fcarsLeft, counters, totalLitresDispensed);
            }

            if (keyPress.Key == ConsoleKey.D6 & vehicle.Count > 0 || keyPress.Key == ConsoleKey.NumPad6 & vehicle.Count > 0)
            {
                PumpSelect(2, lane2, vehicle);
                GUI.LoadGui(lane1, lane2, lane3, vehicle, fcarsLeft, counters, totalLitresDispensed);
            }

            //Lane 3
            if (keyPress.Key == ConsoleKey.D7 & vehicle.Count > 0 || keyPress.Key == ConsoleKey.NumPad7 & vehicle.Count > 0)
            {
                PumpSelect(0, lane3, vehicle);
                GUI.LoadGui(lane1, lane2, lane3, vehicle, fcarsLeft, counters, totalLitresDispensed);
            }

            if (keyPress.Key == ConsoleKey.D8 & vehicle.Count > 0 || keyPress.Key == ConsoleKey.NumPad8 & vehicle.Count > 0)
            {
                PumpSelect(1, lane3, vehicle);
                GUI.LoadGui(lane1, lane2, lane3, vehicle, fcarsLeft, counters, totalLitresDispensed);
            }

            if (keyPress.Key == ConsoleKey.D9 & vehicle.Count > 0 || keyPress.Key == ConsoleKey.NumPad9 & vehicle.Count > 0)
            {
                PumpSelect(2, lane3, vehicle);
                GUI.LoadGui(lane1, lane2, lane3, vehicle, fcarsLeft, counters, totalLitresDispensed);
            }

            if (keyPress.Key == ConsoleKey.Escape)
            {
                fProgramRun = false;
                return(fProgramRun);
            }

            fProgramRun = true;
            return(fProgramRun);
        }
Esempio n. 3
0
 /// <summary>
 /// Calls the GUI to be loaded. Has to take most variables to present them on screen.
 /// </summary>
 /// <param name="lane1"></param>
 /// <param name="lane2"></param>
 /// <param name="lane3"></param>
 /// <param name="vehicleQueue"></param>
 /// <param name="carsLeft"></param>
 public static void LoadGui(Lane lane1, Lane lane2, Lane lane3, List <Vehicle> vehicleQueue, int carsLeft, Counters counters, float totalLitresDispensed)
 {
     Console.Clear();
     LaneAndDetails(lane1, lane2, lane3, vehicleQueue, carsLeft, counters, totalLitresDispensed);
     TextInfo(lane1, lane2, lane3);
     Console.WriteLine("Type a pump number to send a car: ");
     Console.WriteLine("Or press [ESC] to logout");
 }
        public static void Run()
        {
            //initialise list of vehicle objects to be used for vehicle queue
            List <Vehicle> vehicles = new List <Vehicle>();

            //create 3 lanes for 9 pump stations
            Lane     lane1    = new Lane();
            Lane     lane2    = new Lane();
            Lane     lane3    = new Lane();
            GUI      gui      = new GUI();
            Counters counters = new Counters();

            //initialise counter variables
            int   carTimerCounter      = 0;
            int   carsLeft             = 0;
            float totalLitresDispensed = 0f;
            //float placeholderTotalLitresDispensed = 0f;
            float pricePerLitre = 1.15f;

            //setup pay variables
            DateTime loginTime    = DateTime.Now; //Established on program initialisation so we can calculate pay upon logout
            float    payPerMinute = 8.95f / 60;   //Establish pay per minute, makes it easier to calculate pay later on.

            bool programRun = true;

            Random rng = new Random();

            GUI.LoadGui(lane1, lane2, lane3, vehicles, carsLeft, counters, totalLitresDispensed);


            //start program loop
            while (programRun)
            {
                Thread.Sleep(100);

                //Checks for user input to allow user to select a pump
                if (Console.KeyAvailable)
                {
                    programRun = CheckKeyPress(lane1, lane2, lane3, vehicles, carsLeft, counters, totalLitresDispensed, programRun);
                }

                //Uses a random number generator to add a vehicle to vehicles list between 1.5-2.5 seconds
                //Also uses this opportunity to update the number of litres that have been filled on all pumps.
                carTimerCounter++;
                if (carTimerCounter > rng.Next(15, 22))
                {
                    carTimerCounter = 0;
                    vehicles.Add(new Vehicle());
                    totalLitresDispensed = 0;
                    totalLitresDispensed =
                        UpdateTotalLitres(lane1, totalLitresDispensed) +
                        UpdateTotalLitres(lane2, totalLitresDispensed) +
                        UpdateTotalLitres(lane3, totalLitresDispensed);
                    GUI.LoadGui(lane1, lane2, lane3, vehicles, carsLeft, counters, totalLitresDispensed);
                }

                //Runs through every vehicle in list,
                for (int i = 0; i < vehicles.Count; i++)
                {
                    //Checks how long a vehicle has been waiting. Always adds 1 to the wait time (1 = 100ms) and if it is over 25 (2500ms) then
                    //Set internal variable _waitTimeExpired to true
                    vehicles[i].CheckWaitTime();

                    //Checks to see if _waitTimeExpires is true. If it is, removes the vehicle and plays an audio beep to alert user that a vehicle has left the forecourt.
                    if (vehicles[i].VehicleExit())
                    {
                        vehicles.RemoveAt(i);
                        Console.Clear();
                        GUI.LoadGui(lane1, lane2, lane3, vehicles, carsLeft, counters, totalLitresDispensed);
                        Console.Beep();
                        carsLeft++;
                    }
                }

                //Check if any of the vehicles have been filled based on a timer
                FillVehicle(lane1, counters);
                FillVehicle(lane2, counters);
                FillVehicle(lane3, counters);
            }

            //On logout
            //Calculate the total time logged in
            DateTime logoutTime   = DateTime.Now;
            TimeSpan timeLoggedIn = logoutTime - loginTime;

            //Calculate Bonus
            float bonus = (pricePerLitre * totalLitresDispensed) / 100;

            //Convert logged in hours in to minutes so pay calculation is easier later on
            var timeLoggedInHours   = Convert.ToInt32(timeLoggedIn.Hours * 60);
            var timeLoggedInMinutes = Convert.ToInt32(timeLoggedIn.Minutes);

            //Add together hours and minutes (e.g 2 hours and 5 minutes should be 125) and times it by the pay per minute
            float totalPay = payPerMinute * (timeLoggedInMinutes + timeLoggedInHours) + bonus;

            //Present info to user
            Console.Clear();
            Console.WriteLine("Logging out of system");
            Console.WriteLine($"You were logged on to the system for {timeLoggedInHours} hours,{timeLoggedIn.Minutes} minutes. ");
            Console.WriteLine($"You dispensed a total of {Math.Round(totalLitresDispensed)} litres at a total cost of £{pricePerLitre * totalLitresDispensed} ");
            Console.WriteLine($"At £{Math.Round(payPerMinute*60,2)} per hour with a £{Math.Round(bonus,2)} bonus you have earned £{Math.Round(totalPay,2)}");
            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }