Пример #1
0
 public Trafficlight(SimControl sim, Tile road, Point Position, int LaneType)
 {
     this.LaneType = LaneType;
     this.road = road;
     this.Position = Position;
     sc = sim;
 }
Пример #2
0
 /// <summary>
 /// Based on the method UpdateLanes in Tile
 /// this method is called when the lanes are updated.
 /// </summary>
 /// <param name="s"></param>
 /// <param name="direction"></param>
 /// <param name="lanesIn"></param>
 /// <param name="lanesOut"></param>
 public override void UpdateLanes(SimControl s, int direction, int lanesIn, int lanesOut)
 {
     if (directions.Contains(direction))
     {
         lanes[direction * 2 - 1] = lanesOut;
         lanes[direction * 2 - 2] = lanesIn;
     }
     control = new TrafficlightControl(s, this, 3, NotDirection, lanes, position);
 }
Пример #3
0
        protected static System.Security.Cryptography.RNGCryptoServiceProvider rnd;//om de auto's een willekeurige kant op te laten gaan

        public Simulation(SimControl simControl)
        {
            rnd = new System.Security.Cryptography.RNGCryptoServiceProvider();
            this.simControl = simControl;
            this.simStarted = false;
            spawnerList = new List<Spawner>();
            waitingCars = 0;
            simSleep = 70;
            extraSpeed = 0;
            efficiencyNumbers = new List<string[]>();
            
        }
Пример #4
0
        /// <summary>
        /// Constructor used by Crossroad, based on the constructor in Tile
        /// here all default values of the Crossroad are set.
        /// </summary>
        /// <param name="sim"></param>
        public Crossroad(SimControl sim)
        {
            this.name = "Crossroad";
            this.lanes = new int[] { 1, 1, 1, 1, 1, 1, 1, 1 };

            control = new TrafficlightControl(sim, this, 4, 5, lanes);
            directions.Add(1);
            directions.Add(2);
            directions.Add(3);
            directions.Add(4);
            int totalLanes = CountLanes(lanes);
            Initialize();
        }
Пример #5
0
        /// <summary>
        /// Constructor used by fork, based on the constructor in Tile
        /// here all default values of the Spawner are set.
        /// </summary>
        /// <param name="sim"></param>
        /// <param name="direction"></param>
        public Spawner(SimControl sim, int direction)
        {
            this.name = "Spawner";
            carsSpawnChance = 3;
            spawnLane = 0;
            this.lanesIn = 1;
            this.lanesOut = 1;
            this.spawnPerTick = 0.05;
            directions.Add(direction);
            currentSpawn = 1;
            rnd = new System.Security.Cryptography.RNGCryptoServiceProvider();


        }
Пример #6
0
 public static bool TileConnectionisValid(SimControl simcontrol, Tile currentBuildTile,Point tilePosition)
 {
     if (currentBuildTile.name == "Crossroad" || currentBuildTile.name == "Fork")
     {
         foreach (Tile t in simcontrol.simulationMap.GetSurroundingTiles(new Point((tilePosition.X/100)*100,(tilePosition.Y/100)*100)))
         {
             if (t != null && (t.name.Equals("Fork") || t.name.Equals("Crossroad")))
             {
                 return false;
             }
         }
     }
     return true;
 }
Пример #7
0
        /// <summary>
        /// Based on the method UpdateLanes in Tile
        /// this method is called when the lanes are updated.
        /// </summary>
        /// <param name="s"></param>
        /// <param name="direction"></param>
        /// <param name="lanesIn"></param>
        /// <param name="lanesOut"></param>
        public override void UpdateLanes(SimControl s, int direction, int lanesIn, int lanesOut)
        {
            if (direction == StartDirection)
            {
                this.lanesLowToHigh = lanesIn;
                this.lanesHighToLow = lanesOut;
            }
            if (direction == EndDirection)
            {


                this.lanesLowToHigh = lanesOut;
                this.lanesHighToLow = lanesIn;
            }
        }
Пример #8
0
 /*controleert of de tile een rechte weg is en checkt of de weg naar de goede kant doorloopt zodat je een hele weg kunt 
  * maken door rechtdoor te slepen. Hierdoor kun je alleen rechte wegen door slepen op de kaart aanbrengen. Dit verhoogt 
  * het gebruiksgemak omdat het wegen leggen zo een stuk sneller gaat.
 */
 public static bool TileIsStraight(SimControl s, Point mouseDown, Point mousePoint)
 {
     if (s.currentBuildTile.name == "Road" && s.state == "building")
     {
         Road tile = (Road)s.currentBuildTile;
         if ((tile.StartDirection + tile.EndDirection) % 2 == 0)
         {
             if (tile.StartDirection == 2 && mouseDown.Y < mousePoint.Y && mouseDown.Y + 100 > mousePoint.Y)
                 return true;
             if (tile.StartDirection == 1 && mouseDown.X < mousePoint.X && mouseDown.X + 100 > mousePoint.X)
                 return true;
         }
     }
     return false;
 }
Пример #9
0
 /// <summary>
 /// Constructor used by fork, based on the constructor in Tile
 /// here all default values of the Fork are set.
 /// </summary>
 /// <param name="sim"></param>
 /// <param name="notDirection"></param>
 public Fork(SimControl sim, int notDirection)
 {
     this.name = "Fork";
     this.lanes = new int[] { 1, 1, 1, 1, 1, 1, 1, 1 };
     this.notDirection = notDirection;
     lanes[notDirection * 2 - 2] = 0;
     lanes[notDirection * 2 - 1] = 0;
     directions.Add(1);
     directions.Add(2);
     directions.Add(3);
     directions.Add(4);
     directions.Remove(notDirection);
     control = new TrafficlightControl(sim, this, 3, notDirection, lanes);
     int totalLanes = CountLanes(lanes);
     Initialize();
 }
        public TrafficlightControl(SimControl sim, Tile road, int Directions, int NotDirection, int[] NumberOfLanes)
        {
            trafficlightList = new List<LaneTrafficlight>();

            NumberOfDirections = Directions;
            this.road = road;
            this.simcontrol = sim;
            RemoveOldTrafficlights();
            for (int i = 0; i < 4; i++)
            {
                if (i != NotDirection - 1)
                {
                    trafficlightList.Add(new LaneTrafficlight(sim, road, i, NumberOfLanes[i * 2]));
                }
            }
        }
Пример #11
0
        //["Spawner", "Road", "Fork","Crossroad"];

        public static bool CheckValidConnections(SimControl s)
         {
             s.simulationMap.CreateMap();
            foreach (Tile t in s.simulationMap.GetMap())
             {
                foreach (int direction in t.Directions)
                {
                    if (s.simulationMap.GetSurroundingTiles(t.position)[direction - 1] == null)
                     {
                         Tile OtherTile = s.simulationMap.GetSurroundingTiles(t.position)[direction - 1];
                        if (OtherTile == null || !OtherTile.doesConnect(direction))
                            return false;
                        return false;
                     }
                }
             }
             return true;
         }
        public TrafficlightControl(SimControl sim, Tile road, int Directions, int NotDirection, int[] NumberOfLanes, Point position)
        {
            trafficlightList = new List<LaneTrafficlight>();

            NumberOfDirections = Directions;
            this.road = road;
            this.simcontrol = sim;
            RemoveOldTrafficlights();
            for (int i = 0; i < 4; i++)
            {
                if (i != NotDirection - 1)
                {
                    trafficlightList.Add(new LaneTrafficlight(sim, road, i, NumberOfLanes[i * 2]));
                }
            }

            foreach (LaneTrafficlight lane in trafficlightList)
            {
                lane.ChangeValues(position);
            }
        }
Пример #13
0
        public LaneTrafficlight(SimControl sim, Tile road, int Direction, int Lanes)
        {
            this.simcontrol = sim;
            trafficlights = new List<Trafficlight>();
            this.road = road;
            this.Lanes = Lanes;
            this.direction = Direction;

            switch (Lanes)
            {
                //all options for different amounts of lanes, done like this to also give them their proper lanetype
                case 1:
                    CreateSingleLane();
                    break;
                case 2:
                    CreateDoubleLane();
                    break;
                case 3:
                    CreateTripleLane();
                    break;
            }
        }
Пример #14
0
 //methode maakt een kopie van de huidige tile die net getekend is, zodat dezelfde tile nog een keer getekend kan worden.
 public static Tile CopyCurrentTile(SimControl s,Tile startTile)
 {
     Tile tile;
     string tileName = startTile.name;
     switch (tileName)
     {
         case "Spawner": Spawner currentSpawnerTile = (Spawner)startTile;
             tile = new Spawner(s, currentSpawnerTile.Direction);
             break;
         case "Crossroad": tile = new Crossroad(s);
             break;
         case "Road": Road currentRoadTile = (Road)startTile;
             tile = new Road(currentRoadTile.StartDirection, currentRoadTile.EndDirection);
             break;
         case "Fork": Fork currentForkTile = (Fork)startTile;
             tile = new Fork(s, currentForkTile.NotDirection);
             break;
         default: tile = new Crossroad(s);
             break;
     }
     return tile;
 }
Пример #15
0
        /// <summary>
        /// This method is used when a new tile is placed on the map, this causes the tile to update its lanes according to bordering tiles.
        /// </summary>
        /// <param name="simcontrol"></param>
        /// <param name="NotDirection"></param>
        public void UpdateOtherTiles(SimControl simcontrol, int NotDirection)
        {
            if (this.name != "Crossroad")
            {
                if (this.name != "Fork")
                {
                    foreach (int d in directions)
                    {
                        if (d != NotDirection)
                        {
                            int CounterDirection = (d + 1) % 4 + 1;
                            Tile nextTile = simcontrol.simulationMap.GetSurroundingTiles(this.position)[d - 1];
                            if (nextTile != null)
                            {
                                if (this.GetLanesOut(d) != nextTile.GetLanesIn(CounterDirection) || nextTile.GetLanesOut(CounterDirection) != this.GetLanesIn(d))
                                {
                                    nextTile.UpdateLanes(simcontrol, CounterDirection, this.GetLanesOut(d), this.GetLanesIn(d));
                                    nextTile.UpdateOtherTiles(simcontrol, CounterDirection);
                                }
                            }
                        }
                    }
                }
                else
                {
                    Fork forkTile = (Fork)this;
                    if ((NotDirection == (forkTile.NotDirection + 2) % 4 + 1 || NotDirection == (forkTile.NotDirection) % 4 + 1))
                    {
                        int ForkNotDirection = (NotDirection + 1) % 4 + 1;
                        forkTile.UpdateLanes(simcontrol, ForkNotDirection, this.GetLanesOut(NotDirection), this.GetLanesIn(NotDirection));
                        Tile otherTile = simcontrol.simulationMap.GetSurroundingTiles(this.position)[ForkNotDirection - 1];
                        if (otherTile != null)
                        {
                            otherTile.UpdateLanes(simcontrol, NotDirection, this.GetLanesIn(NotDirection), this.GetLanesOut(NotDirection));
                            otherTile.UpdateOtherTiles(simcontrol, NotDirection);
                        }

                    }
                }
            }
            simcontrol.backgroundBC.AddObject(this.DrawImage(), this.position);
        }
Пример #16
0
 /// <summary>
 /// Removes a vehicle on a tile, this is used when a vehicle leaves the map on a spawner
 /// also removes a vehicle when a vehicle leaves a tile to enter another.
 /// </summary>
 /// <param name="sim"></param>
 /// <param name="v"></param>
 /// <param name="Side"></param>
 /// <param name="lane"></param>
 public void RemoveVehicle(SimControl sim, Vehicle v, int lastSide, int Side, int lane)
 {
     List<List<Vehicle>> sideVehicles = vehicles[lastSide - 1];
     List<Vehicle> laneVehicles = sideVehicles[lane];
     laneVehicles.Remove(v);
     numberOfVehicles--;
     //looks if there is space for other cars to come on the tile
     if (laneVehicles.Count < 5 && this.name != "Spawner" && this.name != "Crossroad" && this.name != "Fork")
     {
         Tile lastTile = sim.simulationMap.GetSurroundingTilesSim(this.position)[(lastSide + 1) % 4];
         if (lastTile != null)
             lastTile.Access[lastSide - 1, lane] = true;
     }
 }
Пример #17
0
 /// <summary>
 /// Sets the values given to the tile when the tile is placed on the map.
 /// </summary>
 /// <param name="s"></param>
 /// <param name="position"></param>
 public virtual void SetValues(SimControl s, Point position)
 {
     this.position.X = (position.X / 100) * 100;
     this.position.Y = (position.Y / 100) * 100;
     this.UpdateFromOtherTile(s, 0);
 }
Пример #18
0
 /// <summary>
 /// Based on the method UpdateLanes in Spawner
 /// this method is called when the lanes are updated.
 /// </summary>
 /// <param name="s"></param>
 /// <param name="direction"></param>
 /// <param name="lanesIn"></param>
 /// <param name="lanesOut"></param>
 public override void UpdateLanes(SimControl s, int direction, int lanesIn, int lanesOut)
 {
     if (direction == this.Direction)
     {
         this.lanesIn = lanesIn;
         this.lanesOut = lanesOut;
         DrawSpawnerBlock(s);
     }
 }
Пример #19
0
 /// <summary>
 /// Adds a vehicle to the tile.
 /// </summary>
 /// <param name="sim"></param>
 /// <param name="v"></param>
 /// <param name="Side"></param>
 /// <param name="lane"></param>
 public void AddVehicle(SimControl sim, Vehicle v, int Side, int lane)
 {
     List<List<Vehicle>> sideVehicles = vehicles[Side - 1];
     List<Vehicle> laneVehicles = sideVehicles[lane];
     laneVehicles.Add(v);
     numberOfVehicles++;
     //returns false if the tile is full
     if (laneVehicles.Count > 5 && this.name != "Spawner" && this.name != "Crossroad" && this.name != "Fork")
     {
         Tile lastTile = sim.simulationMap.GetSurroundingTiles(this.position)[(Side + 1) % 4];
         lastTile.Access[Side - 1, lane] = false;
     }
 }
Пример #20
0
        public SimWindow(Size size, WindowSelect windowselect)
        {
            this.Size = size;
            this.windowselect = windowselect;
            sim = new SimControl(this.ClientSize, this);
            this.BackColor = Color.Green;

            //Variable om de elementhosten afhankelijk te maken van het scherm en andere elementhosten
            breedteScherm = Screen.PrimaryScreen.Bounds.Width;
            hoogteScherm = Screen.PrimaryScreen.Bounds.Height;
            hoogteBovenBalk = 80;
            hoogteOnderBalk = 100;
            hoogteInfoBalk = (hoogteScherm - (hoogteBovenBalk + hoogteOnderBalk));
            yLocatieOnderBalk = (hoogteScherm - hoogteOnderBalk);
            xLocatieOnderBalk = (breedteScherm / 7) * 2;
            breedteInfoBalk = breedteScherm / 6;
            breedteOnderBalk = ((breedteScherm / 3));

            using (Graphics graphics = this.CreateGraphics())
            {
                breedteBovenSchermLinks = (260 * (int)graphics.DpiX) / 96;
                breedteBovenSchermRechts = ((55 * 4) * (int)graphics.DpiX) / 96;
                breedteInfoBalk = ((300) * (int)graphics.DpiX) / 96;
                xLocatieOnderBalk = (((breedteScherm / 8) * 2) * (int)graphics.DpiX) / 96;
            }

            InfoBalk = new InfoBalk(windowselect);
            ExtraButtonsOS = new ExtraButtonsOS(windowselect, InfoBalk);
            OnderScherm = new OnderScherm(windowselect, InfoBalk, ExtraButtonsOS, extraButtonsHost, breedteOnderBalk, yLocatieOnderBalk, xLocatieOnderBalk, hoogteOnderBalk);
            BovenSchermLinks = new BovenSchermLinks(windowselect, InfoBalk, OnderScherm);
            BovenSchermRechts = new BovenSchermRechts(windowselect, InfoBalk, OnderScherm, breedteScherm, breedteInfoBalk, hoogteBovenBalk);

            extraButtonsHost = new ElementHost()
            {
                Height = 200,
                Width = 100,
                Location = new Point(this.Size),
                Child = ExtraButtonsOS,
            };
            this.Controls.Add(extraButtonsHost);

            bovenHostLinks = new ElementHost()
            {
                BackColor = Color.Transparent,
                Height = hoogteBovenBalk,
                Width = breedteBovenSchermLinks,
                Location = new Point(10, 10),
                Child = BovenSchermLinks,
            };
            this.Controls.Add(bovenHostLinks);

            bovenHostRechts = new ElementHost()
            {
                BackColor = Color.Transparent,
                Height = hoogteBovenBalk,
                Width = breedteBovenSchermRechts,
                Location = new Point((breedteScherm - breedteBovenSchermRechts), 0),
                Child = BovenSchermRechts,
            };
            this.Controls.Add(bovenHostRechts);

            onderHost = new ElementHost()
            {
                BackColor = Color.Transparent,
                Location = new Point(xLocatieOnderBalk, yLocatieOnderBalk),
                Height = hoogteOnderBalk,
                Width = breedteOnderBalk,
                Child = OnderScherm,
            };
            this.Controls.Add(onderHost);

            infoHost = new ElementHost()
            {
                BackColor = Color.Transparent,
                Location = new Point(this.Size),
                Height = hoogteInfoBalk,
                Width = breedteInfoBalk,
                Child = InfoBalk,
            };
            this.Controls.Add(infoHost);

            this.Controls.Add(sim);

        }
Пример #21
0
 private void DrawSpawnerBlock(SimControl s)
 {
     for (int i = this.position.X; i < this.position.X + 100; i++)
         for (int j = this.position.Y; j < this.position.Y + 100; j++)
             s.trafficlightBC.bitmap.SetPixel(i, j, Color.Transparent);
     Bitmap image = new Bitmap(100, 100);
     DrawTile.drawSpawnerBlock(Graphics.FromImage(image), Direction, lanesOut, lanesIn);
     s.trafficlightBC.AddObject(image, this.position);
 }
Пример #22
0
 /// <summary>
 /// spawns a new car with a randomiser to make the spawns come at random moments
 /// </summary>
 /// <param name="sim"></param>
 public void Spawn(SimControl sim)
 {
     Byte[] random;
     random = new Byte[1];
     rnd.GetBytes(random);
     if (random[0] % carsSpawnChance == 0)
     {
         spawnLane = ((random[0] * 10) / 8) % lanesOut;
         List<List<Vehicle>> vehicleList = vehicles[this.Direction - 1];
         if (vehicleList[spawnLane].Count < 4)
         {
             Vehicle auto = createVehicle(spawnLane);
             auto.endPosition = sim.simulation.GetEndPosition(this, auto);
             AddVehicle(sim, auto, Direction, spawnLane);
             sim.totalCars++;
         }
     }
     currentSpawn--;
 }
Пример #23
0
        /// <summary>
        /// method called on each gametick.
        /// </summary>
        /// <param name="sim"></param>
        /// <param name="extraSpeed"></param>
        /// <param name="extraTime"></param>
        public void Tick(SimControl sim, int extraSpeed, double extraTime)
        {
            currentSpawn += (spawnPerTick * (extraSpeed + 1)) + ((extraTime / 50) * spawnPerTick);

            if (currentSpawn >= 1)
            {
                Spawn(sim);
            }
        }
Пример #24
0
        /// <summary>
        /// Based on the method UpdateLanes in Tile
        /// this method is called when the lanes are updated.
        /// </summary>
        /// <param name="s"></param>
        /// <param name="direction"></param>
        /// <param name="lanesIn"></param>
        /// <param name="lanesOut"></param>
        public override void UpdateLanes(SimControl s, int direction, int lanesIn, int lanesOut)
        {

        }
Пример #25
0
        /// <summary>
        /// Based on the method SetValues in Tile
        /// sets the values given to the Fork when the Fork is placed on the map.
        /// </summary>
        /// <param name="s"></param>
        /// <param name="position"></param>
        public override void SetValues(SimControl s, Point position)
        {
            base.SetValues(s, position);

            control.ChangeValues(position);
        }
Пример #26
0
 /// <summary>
 /// Based on the method UpdateLanes in Tile
 /// this method is called when the lanes are updated.
 /// </summary>
 /// <param name="s"></param>
 /// <param name="direction"></param>
 /// <param name="lanesIn"></param>
 /// <param name="lanesOut"></param>
 public override void UpdateLanes(SimControl s, int direction, int lanesIn, int lanesOut)
 {
     lanes[direction * 2 - 1] = lanesOut;
     lanes[direction * 2 - 2] = lanesIn;
     control = new TrafficlightControl(s, this, 4, 5, lanes, position);
 }
Пример #27
0
 /// <summary>
 /// Based on the method SetValues in Tile
 /// sets the values given to the Spawner when the Spawner is placed on the map.
 /// </summary>
 /// <param name="s"></param>
 /// <param name="position"></param>
 public override void SetValues(SimControl s, Point position)
 {
     base.SetValues(s, position);
     DrawSpawnerBlock(s);
 }
Пример #28
0
        /// <summary>
        /// Based on the method SetValues in Tile.
        /// </summary>
        /// <param name="s"></param>
        /// <param name="position"></param>
        public override void SetValues(SimControl s, Point position)
        {

        }
Пример #29
0
 /// <summary>
 /// Called when the lanes are updated.
 /// </summary>
 /// <param name="s"></param>
 /// <param name="direction"></param>
 /// <param name="lanesIn"></param>
 /// <param name="lanesOut"></param>
 public abstract void UpdateLanes(SimControl s, int direction, int lanesIn, int lanesOut);
Пример #30
0
 public SimulationMap(SimControl simControl)
 {
     this.simControl = simControl;
     tileList = new List<Tile>();
 }