internal static void FillCar(CarPictureBox car, FuelDispenserView fuelDispenser)
        {
            var carView = car.Tag as CarView;

            carView.FuelRemained += fuelDispenser.GetFuelFromTank();

            if (fuelDispenser.ChosenFuelTank.IsEmpty && !_isRefilling)
            {
                CallRefueller(fuelDispenser.ChosenFuelTank);
                _isRefilling = true;
            }

            if (((CashCounterView)CashCounter.Tag).IsFull && !_isCollectingMoney)
            {
                CallCollector();
                _isCollectingMoney = true;
            }

            // test

            if (carView.FuelRemained >= carView.DesiredFilling)
            {
                StopFilling(car, fuelDispenser);
            }
        }
        internal static void StartFilling(CarPictureBox car, PictureBox fuelDispenser)
        {
            var carView           = car.Tag as CarView;
            var fuelDispenserView = (FuelDispenserView)fuelDispenser.Tag;

            fuelDispenserView.ChooseFuelTank(FuelTanksList, carView.Fuel);

            carView.PayForOrderedFuel((CashCounterView)CashCounter.Tag);

            car.IsFilling            = true;
            fuelDispenserView.IsBusy = true;
        }
Example #3
0
        private static void ChooseFuelDispenser(CarPictureBox car)
        {
            var carView = car.Tag as CarView;

            PictureBox        optimalFuelDispenser = ModelingProcessor.FuelDispensersList[0];
            FuelDispenserView fuelDispenserView    = (FuelDispenserView)optimalFuelDispenser.Tag;
            var minQueue = fuelDispenserView.CarsInQueue;

            // Looking for Fuel Dispenser with minimal queue
            foreach (var fuelDispenser in ModelingProcessor.FuelDispensersList)
            {
                fuelDispenserView = (FuelDispenserView)fuelDispenser.Tag;
                if (fuelDispenserView.CarsInQueue < minQueue)
                {
                    minQueue             = fuelDispenserView.CarsInQueue;
                    optimalFuelDispenser = fuelDispenser;
                }
            }

            carView.ChosenFuelDispenser = optimalFuelDispenser;
            fuelDispenserView           = (FuelDispenserView)optimalFuelDispenser.Tag;
            fuelDispenserView.CarsInQueue++;
            carView.IsFuelDispenserChosen = true;

            int   destPointX;
            int   destPointY;
            Point destPoint;

            // Additional points for better graphics
            destPointX = optimalFuelDispenser.Left - DestinationPointsDefiner.FuelingPointDeltaX;
            destPointY = optimalFuelDispenser.Bottom + ElementSizeDefiner.TopologyCellSize - 10;
            destPoint  = new Point(destPointX, destPointY);

            car.AddDestinationPoint(destPoint);

            destPointX = optimalFuelDispenser.Left + DestinationPointsDefiner.FuelingPointDeltaX;
            destPointY = optimalFuelDispenser.Bottom + DestinationPointsDefiner.FuelingPointDeltaY;
            destPoint  = new Point(destPointX, destPointY);

            // The main point of fueling
            car.AddDestinationPoint(destPoint);

            // Additional points for better graphics
            destPointX = optimalFuelDispenser.Right /*- TopologyCellSize / 2*/;
            destPoint  = new Point(destPointX, destPointY + ElementSizeDefiner.CarHeight + 5);
            car.AddDestinationPoint(destPoint);
        }
        private static void StopFilling(CarPictureBox car, FuelDispenserView fuelDispenser)
        {
            var carView = car.Tag as CarView;

            if (carView.FuelRemained > carView.TankVolume)
            {
                carView.FuelRemained = carView.TankVolume;

                var fuelSurplus = carView.FuelRemained - carView.TankVolume;
                fuelDispenser.ReturnFuelToTank(fuelSurplus);
            }

            car.IsFilling = false;
            car.IsFilled  = true;
            fuelDispenser.CarsInQueue--;
            fuelDispenser.IsBusy = false;
        }