// Constructor
        public CarAgent(int paramID, CarAgent[] listCars, World world, Peage[] listPeages)
        {
            // unique ID attribution
            // Well... unique for as long as you only look at existing cars.
            id = paramID;
            flagAbort = false;
            flagPaid = false;
            flagPaying = false;
            flagCloseToCounter = false;
            flagCounterUpdated = false;
            theWorld = world;
            isBraking = 0;
            wasBraking = 0;

            // Roll of the speed mult.
            int rollSpeedMult = MainWindow.rnd.Next(0, 7);
            SpeedMult = 1 - ((rollSpeedMult - 3) / 100); // = 0.97 0.98 0.99 1 1.01 1.02 1.03

            // Payment type choice (0 = Télépéage, 1 = Others)
            int rollPayment = MainWindow.rnd.Next(0, 101);
            if (rollPayment < T_RATE)
            {
                paymentType = 0;
            }
            else
            {
                paymentType = 1;
            }
            // Choix de la couleur (if Télépéage, Orange)
            if (paymentType == 1)
            {
                int caseSwitch = MainWindow.rnd.Next(1,4); // 3 different colors
                switch (caseSwitch)
                {
                    case 1:
                        color = "white";
                        break;
                    case 2:
                        color = "black";
                        break;
                    case 3:
                        color = "grey";
                        break;
                }
            }
            else
            {
                color = "orange";
            }

            //road choice
            // TODO - Le placer sur une des trois voies, si y'a déjà une voiture, on tente de le placer autre part.
            PosX = -19;

            int nbRoad = 0;
            // Télépéage can't spawn on road 3. Non-télépéage can't spawn on road 1.
            if (PaymentType == 0)
            {
                nbRoad = MainWindow.rnd.Next(0, 2);
            }
            else
            {
                nbRoad = MainWindow.rnd.Next(1, 3);
            }
            road = world.roadsArray[nbRoad];
            PosY = road.PosY;
            targetY = PosY;

            // First Range Calculation for spawn-eligibility on the selected road.
            bool spawnable = false;
            bool pass;
            int attempts = 1;

            if (MainWindow.carCount > 0)
            {
                while (spawnable == false && attempts < 3)
                {
                    pass = true;

                    foreach (CarAgent car in listCars)
                    {
                        if (car != null)
                        {
                            if (car.Road == road) {
                                if (DistanceTo(car) < 70)
                                {
                                    pass = false;
                                    break;
                                }
                            }
                        }
                    }

                    if (pass == true)
                    {
                        spawnable = true;
                    }

                    else
                    {
                        if(nbRoad == 2 && PaymentType == 1) // Non-Télépéage is restricted to road 2 and 3.
                        {
                            nbRoad = 1;
                        }
                        else if (nbRoad == 1 && PaymentType == 0) // Télépéage is restricted to road 1 and 2.
                        {
                            nbRoad--; // Attempting road 1 since we didn't try it.
                        }
                        else
                        {
                            nbRoad++;
                        }
                        attempts++;
                        road = world.roadsArray[nbRoad];
                        PosY = road.PosY;
                        targetY = PosY;
                    }
                }

                if (attempts > 2)
                {
                    flagAbort = true;
                }
            }

            pickTargetCounter(listPeages);
            rollTimeAtCounter();

            proximity = (Road.MaxSpeedRoad * 2);

            // Obstacle detection : For cars
            proximity = detectProximityCars(proximity, listCars);

            if (proximity == (Road.MaxSpeedRoad * 2))
            {
                speedX = Road.MaxSpeedRoad;
            }
            else if (proximity < MIN_DISTANCE)
            {
                speedX = 0;
            }
            else if (proximity < MIN_DISTANCE * 2)
            {
                speedX = Road.MaxSpeedRoad * 0.1;
            }
            else if (proximity == Road.MaxSpeedRoad)
            {
                speedX = Road.MaxSpeedRoad * 0.5;
            }
            else
            {
                speedX = Road.MaxSpeedRoad * 0.2;
            }

            speedY = 0;
            updateSpeed(listCars, listPeages);
        }
        void MainWindowLoaded(object _sender, RoutedEventArgs _e)
        {
            theWorld = new World();
            theWorld.WorldUpdatedEvent += theWorld_WorldUpdatedEvent;

            DispatcherTimer dispatcherTimer = new DispatcherTimer();
            dispatcherTimer.Tick += dispatcherTimer_Tick;
            dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, CarAgent.STEP);
            dispatcherTimer.Start();
        }