Example #1
0
        public PetrolStation()
        {
            //start the program by setting all the pumps to a free status
            arrayPumps[0] = new PumpClass("Free");
            arrayPumps[1] = new PumpClass("Free");
            arrayPumps[2] = new PumpClass("Free");
            arrayPumps[3] = new PumpClass("Free");
            arrayPumps[4] = new PumpClass("Free");
            arrayPumps[5] = new PumpClass("Free");
            arrayPumps[6] = new PumpClass("Free");
            arrayPumps[7] = new PumpClass("Free");
            arrayPumps[8] = new PumpClass("Free");


            InitializeComponent();
        }
Example #2
0
        /// <summary>
        /// Method that automates which pump should be selected by a spawn car
        /// and changes its status to Busy
        /// if output is 0 then all the pumps are filled
        /// </summary>
        public int SelectAvailablePump()
        {
            //variable the will hold the pump number selected by automation
            int output;

            output = PumpClass.ChangePumpStatus(arrayPumps);

            //change the selected pump to a busy status
            switch (output)
            {
            case 1:

                arrayPumps[output - 1].PumpStatus = "Busy";
                //add the transaction data to the list
                transactionList.Add(new Transaction(1, emptyTank, vehicleType, vehicleFuel, false));

                VehicleLeftDecrement();

                return(output);

            case 2:
                arrayPumps[output - 1].PumpStatus = "Busy";
                //add the transaction data to the list
                transactionList.Add(new Transaction(2, emptyTank, vehicleType, vehicleFuel, false));

                VehicleLeftDecrement();
                return(output);

            case 3:
                arrayPumps[output - 1].PumpStatus = "Busy";
                //add the transaction data to the list
                transactionList.Add(new Transaction(3, emptyTank, vehicleType, vehicleFuel, false));

                VehicleLeftDecrement();
                return(output);

            case 4:
                arrayPumps[output - 1].PumpStatus = "Busy";
                //add the transaction data to the list
                transactionList.Add(new Transaction(4, emptyTank, vehicleType, vehicleFuel, false));

                VehicleLeftDecrement();
                return(output);

            case 5:
                arrayPumps[output - 1].PumpStatus = "Busy";
                //add the transaction data to the list
                transactionList.Add(new Transaction(5, emptyTank, vehicleType, vehicleFuel, false));

                VehicleLeftDecrement();
                return(output);

            case 6:
                arrayPumps[output - 1].PumpStatus = "Busy";
                //add the transaction data to the list
                transactionList.Add(new Transaction(6, emptyTank, vehicleType, vehicleFuel, false));

                VehicleLeftDecrement();

                return(output);

            case 7:
                arrayPumps[output - 1].PumpStatus = "Busy";
                //add the transaction data to the list
                transactionList.Add(new Transaction(7, emptyTank, vehicleType, vehicleFuel, false));

                VehicleLeftDecrement();
                return(output);

            case 8:
                arrayPumps[output - 1].PumpStatus = "Busy";
                //add the transaction data to the list
                transactionList.Add(new Transaction(8, emptyTank, vehicleType, vehicleFuel, false));

                VehicleLeftDecrement();
                return(output);

            case 9:
                arrayPumps[output - 1].PumpStatus = "Busy";
                //add the transaction data to the list
                transactionList.Add(new Transaction(9, emptyTank, vehicleType, vehicleFuel, false));

                VehicleLeftDecrement();
                return(output);

            default:
                Console.WriteLine("All Pumps are busy.");

                noPumpFlag = true;
                //if all the pumps are busy than a queue of vehicles will start
                vehicleWaitTimer.Enabled = true;

                //the queue of waiting vehicles cant be greater than 5
                if (myCounter.VehiclesWaiting < 5)
                {
                    Console.WriteLine(myCounter.VehiclesWaiting);
                    myCounter.VehiclesWaiting = myCounter.VehiclesWaiting + 1;
                    Console.WriteLine(myCounter.VehiclesWaiting);

                    //update the user display
                    vehiclesWaiting.Text = myCounter.VehiclesWaiting.ToString();
                }
                //stop spawning vehicles if there are more than 5 vehicles waiting
                else if (myCounter.VehiclesWaiting >= 5)
                {
                    timer1.Enabled = false;
                }

                return(output);
            }
        }