Example #1
0
        internal static void RouteCar(MoveablePictureBox car)
        {
            if (!car.IsGoesFilling)
            {
                return;
            }

            CarView       carView       = null;
            CollectorView collectorView = null;

            if (car is CarPictureBox)
            {
                carView = car.Tag as CarView;
            }

            if (car is CollectorPictureBox)
            {
                collectorView = car.Tag as CollectorView;
            }

            var isOnStation = car.IsOnStation;
            var isFilled    = car.IsFilled;

            // New car
            if (!isOnStation && !isFilled && !car.HasDestPoints())
            {
                GoToEnter(car);
            }

            // Just entered the station
            if (car is CarPictureBox carPictureBox)
            {
                if (isOnStation && !carView.IsFuelDispenserChosen)
                {
                    ChooseFuelDispenser(carPictureBox);
                }
            }

            if (car is CollectorPictureBox collector)
            {
                if (isOnStation && !collectorView.IsGoesToCashCounter)
                {
                    GoToCashCounter(collector);
                }
            }

            // After filling
            if (isOnStation && isFilled)
            {
                GoToExit(car);
                car.IsOnStation = false;
            }
        }
Example #2
0
        private static void GoToExit(MoveablePictureBox car)
        {
            var fillingFinishedPoint = car.GetDestinationPoint();

            car.RemoveDestinationPoint(_modelingForm);

            car.AddDestinationPoint(DestinationPointsDefiner.LeavePointFilled);
            car.AddDestinationPoint(DestinationPointsDefiner.ExitPoint3);
            car.AddDestinationPoint(DestinationPointsDefiner.ExitPoint2);
            car.AddDestinationPoint(DestinationPointsDefiner.ExitPoint1);

            car.AddDestinationPoint(fillingFinishedPoint);
        }
Example #3
0
        internal static Point PreventIntersection(MoveablePictureBox activeCar, DirectionEnum.Direction direction)
        {
            var destPoint = activeCar.GetDestinationPoint();

            foreach (Control c in _modelingForm.PlaygroundPanel.Controls)
            {
                if (!(c is PictureBox) || c.Tag == null || c == activeCar)
                {
                    continue;
                }

                var pictureBox = (PictureBox)c;

                if (!activeCar.Bounds.IntersectsWith(pictureBox.Bounds))
                {
                    continue;
                }

                // Another Car
                if (pictureBox is MoveablePictureBox)
                {
                    var anotherCar = pictureBox;

                    switch (direction)
                    {
                    case DirectionEnum.Direction.Up:
                    {
                        activeCar.Top = anotherCar.Bottom;

                        break;
                    }

                    case DirectionEnum.Direction.Right:
                    {
                        activeCar.Left = anotherCar.Left - activeCar.Width;

                        break;
                    }

                    case DirectionEnum.Direction.Down:
                    {
                        activeCar.Top = anotherCar.Top - activeCar.Height;

                        break;
                    }

                    case DirectionEnum.Direction.Left:
                    {
                        activeCar.Left = anotherCar.Right;

                        break;
                    }
                    }
                }


                // Fuel Dispenser
                if (pictureBox.Tag is FuelDispenserView || pictureBox.Tag is CashCounterView)
                {
                    var fuelDispenser = pictureBox;

                    var initialDestinationPoint = activeCar.GetDestinationPoint();

                    bool bypassFromLeft   = false;
                    bool bypassFromRight  = false;
                    bool bypassFromBottom = false;
                    bool bypassFromTop    = false;

                    int newDestX;
                    int newDestY;

                    Point newDestinationPoint1;
                    Point newDestinationPoint2;
                    Point newDestinationPoint3;

                    switch (direction)
                    {
                    case DirectionEnum.Direction.Up:
                    {
                        activeCar.Top = fuelDispenser.Bottom;

                        if (!activeCar.IsBypassingObject)
                        {
                            activeCar.IsBypassingObject = true;
                            // choose where to bypass
                            newDestX = destPoint.X < activeCar.Left
                                        ? fuelDispenser.Left - (activeCar.Width + 5)
                                        : fuelDispenser.Right + (activeCar.Width + 5);


                            if (destPoint.X < activeCar.Left)
                            {
                                newDestX       = fuelDispenser.Left - (activeCar.Width + 5);
                                bypassFromLeft = true;
                            }
                            else
                            {
                                newDestX        = fuelDispenser.Right + (activeCar.Width + 5);
                                bypassFromRight = true;
                            }

                            newDestY = fuelDispenser.Bottom + 10;


                            newDestinationPoint1 = new Point(newDestX,
                                                             newDestY);

                            newDestY             = fuelDispenser.Top + activeCar.Height + 10;
                            newDestinationPoint2 = new Point(newDestX,
                                                             newDestY);

                            activeCar.DeleteDestinationSpot(_modelingForm);
                            activeCar.AddDestinationPoint(newDestinationPoint2);
                            activeCar.AddDestinationPoint(newDestinationPoint1);
                        }

                        break;
                    }

                    case DirectionEnum.Direction.Right:
                    {
                        break;
                    }

                    case DirectionEnum.Direction.Down:
                    {
                        activeCar.Top = fuelDispenser.Top - activeCar.Height;

                        if (!activeCar.IsBypassingObject)
                        {
                            activeCar.IsBypassingObject = true;


                            newDestX = fuelDispenser.Left - (activeCar.Width + 5);

                            newDestY = fuelDispenser.Top - 10;

                            newDestinationPoint1 = new Point(newDestX,
                                                             newDestY);

                            activeCar.DeleteDestinationSpot(_modelingForm);
                            activeCar.AddDestinationPoint(newDestinationPoint1);
                        }

                        break;
                    }

                    case DirectionEnum.Direction.Left:
                    {
                        activeCar.Left = fuelDispenser.Right;

                        if (!activeCar.IsBypassingObject)
                        {
                            activeCar.IsBypassingObject = true;


                            newDestX = fuelDispenser.Right + 10;
                            newDestY = fuelDispenser.Top - (ElementSizeDefiner.CarHeight + 5);

                            newDestinationPoint1 = new Point(newDestX,
                                                             newDestY);

                            if (activeCar.IsFilled)
                            {
                                newDestX = fuelDispenser.Left - ElementSizeDefiner.CarWidth - 5;
                            }
                            else
                            {
                                activeCar.IsGoesHorizontal = true;
                                //newDestX = fuelDispenser.Left - CarWidth - 5 - TopologyCellSize;
                                newDestX = initialDestinationPoint.X + ElementSizeDefiner.TopologyCellSize / 2;
                            }

                            newDestinationPoint2 = new Point(newDestX,
                                                             newDestY);

                            activeCar.FromLeftBypassingPoint = newDestinationPoint2;

                            newDestinationPoint3 = new Point(fuelDispenser.Left - 20,
                                                             destPoint.Y - 20);

                            activeCar.DeleteDestinationSpot(_modelingForm);
                            //activeCarView.AddDestinationPoint(newDestinationPoint3);
                            activeCar.AddDestinationPoint(newDestinationPoint2);
                            activeCar.AddDestinationPoint(newDestinationPoint1);
                        }

                        break;
                    }
                    }
                }
            }

            return(activeCar.GetDestinationPoint());
        }
Example #4
0
 private static void GoToEnter(MoveablePictureBox car)
 {
     car.AddDestinationPoint(DestinationPointsDefiner.EnterPoint3);
     car.AddDestinationPoint(DestinationPointsDefiner.EnterPoint2);
     car.AddDestinationPoint(DestinationPointsDefiner.EnterPoint1);
 }
Example #5
0
        internal static void MoveCarToDestination(MoveablePictureBox car)
        {
            CarView       carView       = null;
            CollectorView collectorView = null;

            if (car is CarPictureBox)
            {
                carView = car.Tag as CarView;
            }

            if (car is CollectorPictureBox)
            {
                collectorView = car.Tag as CollectorView;
            }

            if (car.IsFilling)
            {
                if (car is CarPictureBox carPictureBox)
                {
                    var chosenFuelDispenser = (FuelDispenserView)carView.ChosenFuelDispenser.Tag;

                    ModelingProcessor.FillCar(carPictureBox, chosenFuelDispenser);

                    return;
                }

                if (car is CollectorPictureBox collector)
                {
                    var cashCounter = collectorView.CashCounter.Tag as CashCounterView;

                    ModelingProcessor.CollectCash(collector, cashCounter);

                    return;
                }
            }

            var        destPoint = car.GetDestinationPoint();
            PictureBox destSpot  = car.DestinationSpot;

            var carSpeed = car.IsGoesFilling ? _carSpeedFilling : _carSpeedNoFilling;

            #region MotionLogic

            destPoint = MoveCar(car, destPoint, carSpeed);

            #endregion /MotionLogic


            if (car.DestinationSpot == null)
            {
                destSpot = car.CreateDestinationSpot(destPoint);
                _modelingForm.PlaygroundPanel.Controls.Add(destSpot);
            }

            if (car.Bounds.IntersectsWith(destSpot.Bounds))
            {
                car.RemoveDestinationPoint(_modelingForm);

                car.IsBypassingObject = false;
                //_isGoHorizontal = false;
                //_isGoVertical = false;

                if (destPoint.Equals(DestinationPointsDefiner.EnterPoint3))
                {
                    car.IsOnStation = true;
                }

                if (car.IsGoesHorizontal && destPoint.Equals(car.FromLeftBypassingPoint))
                {
                    car.IsGoesHorizontal = false;
                    //var x = 1;
                }

                if (car is CarPictureBox carPictureBox)
                {
                    foreach (var fuelDispensersDestPoint in DestinationPointsDefiner.FuelDispensersDestPoints.Values)
                    {
                        if (destPoint.Equals(fuelDispensersDestPoint))
                        {
                            ModelingProcessor.StartFilling(carPictureBox, carView.ChosenFuelDispenser);
                            //test
                            //carView.IsFilled = true;
                        }
                    }
                }

                if (car is CollectorPictureBox collector)
                {
                    if (destPoint.Equals(DestinationPointsDefiner.CashCounter))
                    {
                        ModelingProcessor.StartCollectingCash(collector, collectorView.CashCounter.Tag as CashCounterView);
                        return;
                    }
                }

                if (destPoint.Equals(DestinationPointsDefiner.ExitPoint1))
                {
                    car.IsOnStation = false;
                }

                if (destPoint.Equals(DestinationPointsDefiner.LeavePointNoFilling) || destPoint.Equals(DestinationPointsDefiner.LeavePointFilled))
                {
                    _modelingForm.PlaygroundPanel.Controls.Remove(car);
                    car.Dispose();
                }
            }
        }
Example #6
0
        internal static Point MoveCar(MoveablePictureBox car, Point destPoint, int carSpeed)
        {
            var isHorizontalMoving = false;
            var isVerticalMoving   = false;

            if (!car.IsBypassingObject)
            {
                if (!car.IsFilled && !car.IsGoesHorizontal)
                {
                    // Go Up
                    if (car.Top >= destPoint.Y && !isHorizontalMoving)
                    {
                        car.Top -= carSpeed;
                        //car.Image = Properties.Resources.car_32x17__up;
                        isVerticalMoving = true;
                        destPoint        = CarRouter.PreventIntersection(car, DirectionEnum.Direction.Up);
                    }

                    // Go Down
                    if (car.Bottom <= destPoint.Y && !isHorizontalMoving)
                    {
                        car.Top += carSpeed;
                        //car.Image = Properties.Resources.car_64x34__down;
                        isVerticalMoving = true;
                        destPoint        = CarRouter.PreventIntersection(car, DirectionEnum.Direction.Down);
                    }

                    // Go left
                    if (car.Left >= destPoint.X && !isVerticalMoving)
                    {
                        car.Left -= carSpeed;
                        //car.Image = Properties.Resources.car_32x17__left;
                        destPoint = CarRouter.PreventIntersection(car, DirectionEnum.Direction.Left);
                    }

                    // Go Right
                    if (car.Right <= destPoint.X && !isVerticalMoving)
                    {
                        car.Left += carSpeed;
                        //car.Image = Properties.Resources.car_32x17__right;
                    }
                }
                else
                {
                    // Go left
                    if (car.Left >= destPoint.X)
                    {
                        car.Left -= carSpeed;
                        //car.Image = Properties.Resources.car_32x17__left;
                        isHorizontalMoving = true;
                        destPoint          = CarRouter.PreventIntersection(car, DirectionEnum.Direction.Left);
                    }

                    // Go Right
                    if (car.Right <= destPoint.X)
                    {
                        car.Left += carSpeed;
                        //car.Image = Properties.Resources.car_32x17__right;
                        isHorizontalMoving = true;
                    }

                    // Go Up
                    if (car.Top >= destPoint.Y && !isHorizontalMoving)
                    {
                        car.Top -= carSpeed;
                        //car.Image = Properties.Resources.car_32x17__up;
                        destPoint = CarRouter.PreventIntersection(car, DirectionEnum.Direction.Up);
                    }

                    // Go Down
                    if (car.Bottom <= destPoint.Y && !isHorizontalMoving)
                    {
                        car.Top += carSpeed;
                        //car.Image = Properties.Resources.car_32x17__down;
                        destPoint = CarRouter.PreventIntersection(car, DirectionEnum.Direction.Down);
                    }
                }
            }
            else
            {
                // Go left
                if (car.Left >= destPoint.X)
                {
                    car.Left -= carSpeed;
                    //car.Image = Properties.Resources.car_32x17__left;
                    destPoint = CarRouter.PreventIntersection(car, DirectionEnum.Direction.Left);
                }

                // Go Right
                if (car.Right <= destPoint.X)
                {
                    car.Left += carSpeed;
                    //car.Image = Properties.Resources.car_32x17__right;
                }

                // Go Up
                if (car.Top >= destPoint.Y)
                {
                    car.Top -= carSpeed;
                    //car.Image = Properties.Resources.car_32x17__up;
                    destPoint = CarRouter.PreventIntersection(car, DirectionEnum.Direction.Up);
                }

                // Go Down
                if (car.Bottom <= destPoint.Y)
                {
                    car.Top += carSpeed;
                    //car.Image = Properties.Resources.car_32x17__down;

                    destPoint = CarRouter.PreventIntersection(car, DirectionEnum.Direction.Down);
                }
            }

            return(destPoint);
        }