public Trafficlight(SimControl sim, Tile road, Point Position, int LaneType)
 {
     this.LaneType = LaneType;
     this.road = road;
     this.Position = Position;
     sc = sim;
 }
Example #2
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;
 }
        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]));
                }
            }
        }
        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);
            }
        }
Example #5
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;
 }
        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;
            }
        }
Example #7
0
 //returns if there are no other cars standing in front
 private bool DistanceFromCars(Tile t, Vehicle v)
 {
     int distance = 0;//distance between the end of the tile and the last car standing still.
     List<List<Vehicle>> vehicleList = simControl.simulationMap.GetTileMea(t.position.X, t.position.Y).vehicles[v.Direction - 1];
     distance = vehicleList[v.Lane].IndexOf(v) * 16;
     if (t.name == "Fork" || t.name == "Crossroad")
         return true;
     return CorrectDistance(t, v, distance);
 }
Example #8
0
        /// <summary>
		/// Draws a blue line surrounding the selected tile
        /// </summary>
        /// <param name="mea">location of the mouse</param>
        public void DrawSelectLine(Point mea)
        {
			/// If the point has a road, draw blue line
            if (simulationMap.GetTileMea(mea.X, mea.Y) != null)
            {
                Tile selectTile = new SelectTile();

                /// Drawing blue line
                selectTile.SetValues(this, new Point(mea.X / 100 * 100, mea.Y / 100 * 100));
                selectTile.DrawImage();

                /// The current selectedTile becomes the oldselectedTile
                oldselectedTile = simulationMap.GetTileMea(mea.X, mea.Y);
                selectedTile = simulationMap.GetTileMea(mea.X, mea.Y);
                UpdateInfoBalkDesign();
                simwindow.BovenSchermRechts.ShowOrHideInfoBalk(true);

            }
			/// If the point doesn't have a road
            else
            {
				/// Remove blue line
                if (selectedTile != null)
                    backgroundBC.AddObject(selectedTile.DrawImage(), selectedTile.position);

				/// Set selectedTile and oldSelectedTile to null
                oldselectedTile = null;
                selectedTile = null;

				/// Hide info screen
                simwindow.BovenSchermRechts.ShowOrHideInfoBalk(false);
            }

            this.Invalidate();
        }
Example #9
0
		/// <summary>
		/// Draw a tile
		/// </summary>
		/// <param name="mea">location of the mouse</param>
		/// <param name="buildTile">tile that has to be drawn</param>
        public void DrawTile(Point mea, Tile buildTile)
        {
            Bitmap tileImage;

            if (Methods.TileConnectionisValid(this, buildTile, mea))
            {
                simwindow.BovenSchermRechts.ShowOrHideInfoBalk(false);
                removeTile(mea);

                AmountOfTiles++;
                //tile is placced in list
                simulationMap.AddTile(buildTile);
                buildTile.SetValues(this, simulationMap.GetPosition(new Point(mea.X, mea.Y)));
                tileImage = buildTile.DrawImage();
                //Map is updated with the new tile
                backgroundBC.AddObject(tileImage, simulationMap.GetPosition(new Point(mea.X, mea.Y)));
                selectedTile = buildTile;
                trafficlightBC.bitmap.MakeTransparent(Color.Green);
				//A new buildTile is created with the same values as before because a new tile can than be clicked in
                currentBuildTile = Methods.CopyCurrentTile(this, buildTile);
                if (buildTile.name == "Crossroad" || buildTile.name == "Fork")
                {
                    this.AmountOfTrafficlights++;
                }
                UpdateInfoBalkDesign();
                this.Invalidate();
            }
        }
Example #10
0
		/// <summary>
		/// Click Open in homescreen
		/// Loads previous saved files
		/// </summary>
		public void Open_Click()
		{
            Tile[] tempTileList = new Tile[(windowselect.simwindow.simcontrol.Size.Width / 100) * (windowselect.simwindow.simcontrol.Size.Height / 100)];
			/// Does this work?
            SimControl simcontrol;
            
			simcontrol = windowselect.simwindow.simcontrol;
            simcontrol.oldselectedTile = null;

			/// Make new stream
			Stream myStream1 = null;
			Stream myStream2 = null;
			Stream dummyStream = null;

			int addLines = 0;
			int totalLines;

			/// New open dialog
			OpenFileDialog openDialog = new OpenFileDialog();

			/// Few basic settings for the opendialog
			//openFileDialog1.InitialDirectory = "c:\\";
			openDialog.Filter = "TrafficSimulation files (*.trs)|*.trs";
			openDialog.FilterIndex = 1;
			openDialog.RestoreDirectory = true;

			if (openDialog.ShowDialog() == DialogResult.OK)
			{
				/// Change cursor to wait cursor
				this.Cursor = Cursors.WaitCursor;

				/// Make new loadwindow with the startposition in the middle
				LoadWindow LoadWin = new LoadWindow();
				LoadWin.StartPosition = FormStartPosition.CenterScreen;
				LoadWin.FormBorderStyle = FormBorderStyle.FixedDialog;
				LoadWin.ControlBox = false;

				/// Try to open the file
				try
				{
					if (openDialog.OpenFile() != null)
					{
						/// Make 3 streams, 1 for the road and spawners, 2 for the forks and crossroads and the dummy for counting
						myStream1 = openDialog.OpenFile();
						myStream2 = openDialog.OpenFile();
						dummyStream = openDialog.OpenFile();

						/// Streamreaders for each stream
						StreamReader dummyReader = new StreamReader(dummyStream);
						StreamReader r1, r2;

						/// Set the number of lines of code that has to be deleted and added
						addLines = 0;

						/// Count the numbers of lines in the file
						string line;
						while ((line = dummyReader.ReadLine()) != null)
						{
							addLines++;
						}

						/// Total amount of lines that has to be run through while loading
						totalLines = addLines * 2;

						/// Set maximums of the progressbar
						LoadWin.progressBar1.Maximum = totalLines;

						/// Show the LoadWindow
						LoadWin.Show();

						/// Clear the map
						simcontrol.backgroundBC.ClearBitmap();
						simcontrol.backgroundBC.bitmap.MakeTransparent(Color.Green);
						simcontrol.trafficlightBC.ClearBitmap();
						simcontrol.trafficlightBC.bitmap.MakeTransparent(Color.Green);
						simcontrol.Invalidate();

						/// Clear the list
						simcontrol.simulationMap.ClearTileList();

						#region Add roads and spawners to the map

						/// Add al the roads to the map
						using (myStream1)
						{
							// Streamreader for stream 1
							r1 = new StreamReader(myStream1);

							// Set value of progressBar1 back to 0 and change maximum
							LoadWin.progressBar1.Value = 0;
							LoadWin.progressBar1.Maximum = (addLines * 2);


							/// Read the file line for line
							while (r1.Peek() >= 0)
							{
								string t = r1.ReadLine();

								// Char that splits the data
								char[] splitChar = { '_' };

								// Array of strings with info about tile
								string[] information = t.Split(splitChar);

								Bitmap tileImage;
								Tile currentBuildTile;
								int roadX;
								int roadY;

								int tilesHorizontal = Size.Width / 100;

								/// You need different information from different tiles
								/// So you need multiple cases, one for each tile
								/// 
								/// Basic information
								///		 0: Tile
								///		 1: X position
								///		 2: Y position
								///	Specific information
								///		 3: Trafficlight strat
								///		 4: Maxspeed for a tile
								///		 5: Begin direction (notDirection for Fork, direction for Spawner)
								///		 6: End direction (only for Road)
								///		 7: laneshightolow, not for Crossroad and Fork
								///		 8: laneslowtohigh, not for Crossroad and Fork
								///		 9: Cars per second in spawner
								
								switch (information[0])
								{
									case "Road":
										/// Make new tile
										currentBuildTile = new Road(Convert.ToInt32(information[5]), Convert.ToInt32(information[6]));

										/// Get the location
										roadX = Convert.ToInt32(information[1]) / 100;
										roadY = Convert.ToInt32(information[2]) / 100;

										/// Set some values
										currentBuildTile.SetValues(simcontrol, new Point((roadX * 100), roadY * 100));
										currentBuildTile.LanesHighToLow = Convert.ToInt32(information[7]);
										currentBuildTile.LanesLowToHigh = Convert.ToInt32(information[8]);
										currentBuildTile.maxSpeed = Convert.ToInt32(information[4]);

										/// Add to list
										tempTileList[(roadX + roadY * 20)] = currentBuildTile;

										/// Draw the tile
										tileImage = currentBuildTile.DrawImage();
										simcontrol.backgroundBC.AddObject(tileImage, new Point(roadX * 100, roadY * 100));

										/// Add 1 to progressBar1/2
										LoadWin.progressBar1.PerformStep();

										break;

									/// Load a spawner to the list
									case "Spawner":
										/// Make new tile
                                        currentBuildTile = new Spawner(windowselect.simwindow.simcontrol, Convert.ToInt32(information[5]));
										Spawner spawner = (Spawner)currentBuildTile;

										/// Get location
										roadX = Convert.ToInt32(information[1]) / 100;
										roadY = Convert.ToInt32(information[2]) / 100;

										/// Set some values
										spawner.maxSpeed = Convert.ToInt32(information[4]);
										spawner.UpdateLanes(simcontrol, Convert.ToInt32(information[5]), Convert.ToInt32(information[7]), Convert.ToInt32(information[8]));
										spawner.SetValues(simcontrol, new Point((roadX * 100), roadY * 100));
										spawner.CarsSpawnChance = Convert.ToInt32(information[9]);

										/// Add to list
										tempTileList[(roadX + roadY * 20)] = currentBuildTile;

										/// Draw the tile
										tileImage = currentBuildTile.DrawImage();
										simcontrol.backgroundBC.AddObject(tileImage, new Point(roadX * 100, roadY * 100));
										simcontrol.Invalidate();

										/// Add 1 to progressBar1/2
										LoadWin.progressBar1.PerformStep();

										break;

									default:
										break;
								}
							}

							/// Copy the tempTileList to tileList
                            foreach (Tile tile in tempTileList)
                            {
                                if (tile != null)
                                {
                                    windowselect.simwindow.simcontrol.simulationMap.AddTile(tile);
                                }
                            }
						}

						#endregion

						#region Add the rest to the map

						using (myStream2)
						{
							r2 = new StreamReader(myStream2);

                            tempTileList = new Tile[(windowselect.simwindow.simcontrol.Size.Width / 100) * (windowselect.simwindow.simcontrol.Size.Height / 100)];
							/// Read the file line for line
							while (r2.Peek() >= 0)
							{
								string t = r2.ReadLine();

								// Char that splits the string
								char[] splitChar = { '_' };

								// Array of strings with info about tile
								string[] information = t.Split(splitChar);

								Bitmap tileImage;
								Tile currentBuildTile;
								int roadX;
								int roadY;

								int tilesHorizontal = Size.Width / 100;

								/// You need different information from different tiles
								/// So you need multiple cases, one for each tile
								/// 
								/// Basic information
								///		 0: Tile
								///		 1: X position
								///		 2: Y position
								///	Specific information
								///		 3: Trafficlight strat
								///		 4: Maxspeed for a tile
								///		 5: Begin direction (notDirection for Fork, direction for Spawner)
								///		 6: End direction (only for Road)
								///		 7: laneshightolow, not for Crossroad and Fork
								///		 8: laneslowtohigh, not for Crossroad and Fork
								///		 9: Cars per second in spawner

								switch (information[0])
								{
									/// Load a fork into the list
									case "Fork":
										/// Make new tile
										currentBuildTile = new Fork(simcontrol, Convert.ToInt32(information[5]));

										/// Get the location
										roadX = Convert.ToInt32(information[1]) / 100;
										roadY = Convert.ToInt32(information[2]) / 100;

										/// Set some values
										currentBuildTile.SetValues(simcontrol, new Point((roadX * 100), roadY * 100));
										currentBuildTile.maxSpeed = Convert.ToInt32(information[4]);
										currentBuildTile.GetControl().strat = Convert.ToInt32(information[3]);

										/// Add to list
										tempTileList[(roadX + roadY * 20)] = currentBuildTile;

										/// Draw the tile
										tileImage = currentBuildTile.DrawImage();
										simcontrol.backgroundBC.AddObject(tileImage, new Point(roadX * 100, roadY * 100));
										simcontrol.Invalidate();

										/// Add 1 to progressBar1/2
										LoadWin.progressBar1.PerformStep();

										break;

									/// Load a crossroad to the list
									case "Crossroad":
										/// Make new tile
										currentBuildTile = new Crossroad(simcontrol);

										/// Get location
										roadX = Convert.ToInt32(information[1]) / 100;
										roadY = Convert.ToInt32(information[2]) / 100;

										/// Set some values
										currentBuildTile.SetValues(simcontrol, new Point((roadX * 100), roadY * 100));
										currentBuildTile.maxSpeed = Convert.ToInt32(information[4]);
										currentBuildTile.GetControl().strat = Convert.ToInt32(information[3]);

										/// Add to list
										tempTileList[(roadX + roadY * 20)] = currentBuildTile;

										/// Draw the tile
										tileImage = currentBuildTile.DrawImage();
										simcontrol.backgroundBC.AddObject(tileImage, new Point(roadX * 100, roadY * 100));
										simcontrol.Invalidate();

										/// Add 1 to progressBar1/2
										LoadWin.progressBar1.PerformStep();

										break;

									default:
										break;
								}
							}

							/// Copy the tempTileList to tileList
							foreach (Tile tile in tempTileList)
							{
								if (tile != null)
								{
									windowselect.simwindow.simcontrol.simulationMap.AddTile(tile);
								}
							}
						}

						#endregion

					}
					/// Set the current building tile to a straight road
					simcontrol.currentBuildTile = new Road(1, 3);
					
					///Set the state to selected
					simcontrol.state = "selected";

					LoadWin.Close();

					/// Set cursor back to an arrow
					this.Cursor = Cursors.Arrow;

					/// New screen
					windowselect.New();			
				}

				/// Throw exception when something is wrong
				catch (Exception ex)
				{
					LoadWin.Close();
					this.Cursor = Cursors.Arrow;

					MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
				}

			}
		}
        //deze wordt gebruikt als de simulatie nog niet is gestart
        public Tile[] GetSurroundingTiles(Point pos)
        {
            Tile[] tileArray = new Tile[4];

            foreach (Tile t in tileList)
            {
                if (t.position.X == pos.X)
                {
                    if (t.position.Y == pos.Y - 100)
                    {
                        tileArray[0] = t;
                    }
                    else if (t.position.Y == pos.Y + 100)
                    {
                        tileArray[2] = t;
                    }
                }
                if (t.position.Y == pos.Y)
                {
                    if (t.position.X == pos.X - 100)
                    {
                        tileArray[3] = t;
                    }
                    else if (t.position.X == pos.X + 100)
                    {
                        tileArray[1] = t;
                    }
                }
            }

            return tileArray;
        }
Example #12
0
        private void GetRandomOutDirection(Tile tile, Vehicle v)
        {
            int newDirection = 0;
            switch (tile.name)
            {
                case "Spawner":
                    newDirection = v.Direction;
                    break;
                case "Road":
                    foreach (int i in tile.Directions)
                    {
                        if (i != ((v.Direction + 1) % 4)+1)
                        {
                            newDirection = i;
                        }
                    }
                    break;
                case  "Crossroad" :
                    switch (tile.GetLanesIn((v.Direction+1)%4+1))
                    {
                        case 1: while (newDirection == 0 || newDirection == (v.Direction + 1) % 4 + 1)
                                    newDirection = RandomNumber(4);
                            break;
                        case 2:
                            
                                switch(v.Lane)
                                {
                                    
                                case 1: int number = RandomNumber(2);
                                    if (number == 1)
                                        newDirection = (v.Direction) % 4 + 1;
                                    else
                                        newDirection = v.Direction;
                                    break;
                                case 0: newDirection = (v.Direction+2) % 4 + 1;
                                    break;
                            }
                            break;
                        case 3:
                            switch (v.Lane)
                            {
                                case 0: newDirection = (v.Direction + 2) % 4 + 1;
                                    break;
                                case 1: newDirection = v.Direction;  
                                    break;
                                case 2: newDirection = (v.Direction) % 4 + 1;
                                    break;
                            }
                            break;
                    }
                    break;
                case "Fork" :
                    switch (tile.GetLanesIn((v.Direction + 1) % 4 + 1))
                        {
                            case 1: while (newDirection == 0 || newDirection == (v.Direction + 1) % 4 + 1 || newDirection == tile.NotDirection)
                                    newDirection = RandomNumber(4);
                                break;
                            case 2:
                                if (v.Direction == (tile.NotDirection + 2) % 4 + 1)
                                {
                                    switch (v.Lane)
                                    {
                                        case 1: newDirection = v.Direction;
                                            break;
                                        case 0: newDirection = (v.Direction + 2) % 4 + 1;
                                            break;
                                    }
                                }
                                else if(v.Direction == (tile.NotDirection) % 4 + 1)
                                {
                                     switch (v.Lane)
                                    {
                                        case 1:  newDirection = (v.Direction) % 4 + 1;
                                            break;
                                        case 0: newDirection = v.Direction;
                                            break;
                                    }   
                                }
                                else
                                {   
                                    switch (v.Lane)
                                    {
                                        case 1: newDirection = (v.Direction) % 4 + 1;
                                            break;
                                        case 0: newDirection = (v.Direction + 2) % 4 + 1;
                                            break;
                                    }
                                }
                            break;

                            case 3:
                                if ((v.Direction + 1) % 4 + 1 == (tile.NotDirection + 2) % 4 + 1)
                                {
                                    switch (v.Lane)
                                    {
                                        case 2:  newDirection = (v.Direction) % 4 + 1;
                                            break;
                                        case 1: newDirection = v.Direction;
                                            break;
                                        case 0: newDirection = v.Direction;
                                            break;
                                    }
                                }
                                else if ((v.Direction + 1) % 4 + 1 == (tile.NotDirection) % 4 + 1)
                                {
                                    switch (v.Lane)
                                    {
                                        case 2: newDirection = v.Direction;
                                            break;
                                        case 1: newDirection = v.Direction;
                                            break;
                                        case 0: newDirection = (v.Direction + 2) % 4 + 1;
                                            break;
                                    }
                                }
                                else
                                {
                                    switch (v.Lane)
                                    {
                                        case 2: newDirection = (v.Direction) % 4 + 1;
                                            break;
                                        case 1: newDirection = (v.Direction) % 4 + 1;
                                            break;
                                        case 0: newDirection = (v.Direction + 2) % 4 + 1;
                                            break;
                                    }
                                }
                                break;
                        }
                    break;
            }
            //if (v.UpdatePoint == 0)
            {
                if (v.Direction - newDirection < 0)
                {
                    v.Bitmap.RotateFlip(RotateFlipType.Rotate90FlipNone);
                }
                v.NextDirection = newDirection;
            }
        }
Example #13
0
        public Point GetEndPosition(Tile tile, Vehicle v)
        {
            int randomLane = 0;
            
            if (tile.name == "Spawner" || tile.name == "Road")
            {
                randomLane = v.Lane;
                //v.Lane = randomLane;
            }
            else
            {
                Tile endTile = simControl.simulationMap.GetConnectingTiles(tile.position)[v.NextDirection - 1];
                int tileLanes = endTile.GetLanesIn((v.NextDirection + 1) % 4 + 1);
                randomLane = Math.Abs(Guid.NewGuid().GetHashCode()) % tileLanes;
                v.Lane = randomLane;
            }



            switch(v.NextDirection)
            {
                case 1:
                    return new Point(tile.position.X + 53 + (randomLane * 16), tile.position.Y );
                case 2:
                    if (v.LastDirection == 1 && v.Direction != 2)
                        return new Point(tile.position.X - v.Bitmap.Height + 100 - 5, tile.position.Y + 53 + (16 * randomLane) - v.Bitmap.Height);
                    else
                        return new Point(tile.position.X - v.Bitmap.Height + 100 - 5, tile.position.Y + 53 + (16 * randomLane));
                case 3:
                    if(v.LastDirection == 4)
                    return new Point(tile.position.X + 37 - (16 * randomLane), tile.position.Y + 100 - v.Bitmap.Height - 5);
                    else
                        return new Point(tile.position.X + 37 - (16 * randomLane), tile.position.Y + 100 - v.Bitmap.Width - 5);
                case 4 :
                    return new Point(tile.position.X+5,tile.position.Y+ 37 -(16*randomLane));
                default :
                    return new Point(0,0);
            }
        }
Example #14
0
 private bool VehicleIsOnEndSpawner(Vehicle v, Tile t)
 {
     if (t.name == "Spawner" && t.Directions.Contains((v.Direction + 1) % 4 + 1))
     {
         switch (v.Direction)
         {
             case 1: if (v.position.Y - v.Speed <= t.position.Y + 15)
                     return true;
                 break;
             case 2: if (v.position.X + v.Speed + 15 >= t.position.X + 85)
                     return true;
                 break;
             case 3: if (v.position.Y + v.Speed + 15 >= t.position.Y + 85)
                     return true;
                 break;
             case 4: if (v.position.X - v.Speed <= t.position.X + 15)
                     return true;
                 break;
         }
     }
     return false;
 }
        public Tile[] GetConnectingTiles(Point pos)
        {
            Tile[] connectingTiles = new Tile[4];

            foreach (int d in GetTile(pos).Directions)
            {
                if (GetSurroundingTiles(pos)[d - 1] != null)
                {
                    connectingTiles[d - 1] = GetSurroundingTiles(pos)[d - 1];
                }
            }

            return connectingTiles;
        }
Example #16
0
 //returns if an object is still on the tile
 private bool StaysOnTile(Tile t, Vehicle v)
 {
     return CorrectDistance(t, v, 0);
 }
Example #17
0
 private void UpdateVehicle(Tile t, Vehicle v)
 {
     if (v.Speed == 0)
         waitingCars--;
     v.Speed = t.MaxSpeed + extraSpeed;
     //if vehicle has to dissapear ----- moet worden vervangen door zwart vlak over de spawner-----
     if (VehicleIsOnEndSpawner(v, t))
     {
         simControl.simulationMap.GetTileMea(t.position.X, t.position.Y).RemoveVehicle(simControl, v, v.Direction, v.LastDirection, v.Lane);
         simControl.totalCars--;
     }
     if (StaysOnTile(t, v))//if vehicle is still on the tile 
     {
         if (DistanceFromCars(t, v))
         {
             //if there are other cars standing in front
             v.Update(t);
         }
         else
         {
             v.Speed = 0;
             waitingCars++;
         }
     }
     else
     {
         if (t.Access[v.NextDirection - 1, v.Lane])//if the next tile is accessible
         {
             //remove vehicle from old tile and add vehicle to new tile
             Tile[] test = simControl.simulationMap.GetSurroundingTilesSim(t.position);
             //simControl.simulationMap.GetTile(t.position).RemoveVehicle(simControl, v, v.LastDirection, v.Lane);
             Tile nextTile = simControl.simulationMap.GetSurroundingTilesSim(t.position)[v.NextDirection - 1];
             simControl.simulationMap.GetTile(t.position).RemoveVehicle(simControl, v, v.Direction, v.Direction, v.oldLane);
             v.reset();
             int oldLane = v.Lane;
             if (nextTile != null)
             {
                 v.Speed = nextTile.maxSpeed;
                 v.LastDirection = v.Direction;
                 v.Direction = v.NextDirection;
                 v.oldLane = v.Lane;
                 nextTile.AddVehicle(simControl, v, v.Direction, v.Lane);
                 GetRandomOutDirection(nextTile, v);
                 v.endPosition = GetEndPosition(nextTile, v);
                 v.Update(nextTile);
             }
             
             
             
         }
         else
         {
             v.Speed = 0;
             waitingCars++;
         }
     }
 }
 public void AddTile(Tile t)
 {
     foreach (Tile tile in tileList)
     {
         if (t.position == tile.position)
         {
             RemoveTile(tile);
             tileList.Add(t);
             break;
         }
     }
     tileList.Add(t);
 }
 public void RemoveTile(Tile t)
 {
     tileList.Remove(t);
 }
Example #20
0
 //calculates the places and returns if the vehicle is allowed to drive
 private bool CorrectDistance(Tile t, Vehicle v, int CarSpace)
 {
     switch (v.NextDirection)
     {
         case 1: if (v.position.Y - v.Speed>= t.position.Y+ CarSpace)
                 return true;
             break;
         case 2: if (v.position.X + v.Speed + v.Bitmap.Width + 5 <= t.position.X + t.size.Width - CarSpace)
                 return true;
             break;
         case 3: if (v.position.Y + v.Speed + v.Bitmap.Width + 5 <= t.position.Y + t.size.Height - CarSpace)
                 return true;
             break;
         case 4: if (v.position.X - v.Speed - 5 >= t.position.X + CarSpace)
                 return true;
             break;
     }
     return false;
 }
Example #21
0
        public void Update(Tile t)
        {
            if (updatePoint == 0)
            {
                Instantiate(endPosition);
                getEndDirection();
            }

            //nodig omdat een update niet altijd een heel getal is.
            tempX += ((double)updateSize.Width / updateLength) * speed;
            tempY += ((double)updateSize.Height / updateLength) * speed;

            // de case voor elke mogelijkheid Direction --> Direction
            // de direction waar de auto vandaan komt en waar hij naar toe gaat gescheiden door een pijl
            switch (direction + "-->" + nextDirection)
            {
                case "1-->1":
                    //aanpassing in de x richting die positief of negatief is
                    while (tempX >= 1)
                    {
                        this.position.X++;
                        tempX--;
                    }
                    while (tempX <= -1)
                    {
                        this.position.X--;
                        tempX++;
                    }
                    //aanpassing in de y richting die altijd negatief is
                    while (tempY <= -1)
                    {
                        position.Y--;
                        tempY++;
                    }
                    break;
                case "1-->2":
                    //aanpassing in de x richting die altijd positief is
                    while (tempX >= 1)
                    {
                        this.position.X++;
                        tempX--;
                    }
                    //aanpassing in de y richting die altijd negatief is
                    while (tempY <= -1)
                    {
                        position.Y--;
                        tempY++;
                    }

                    if (!rotated)
                    {
                        bitmap.RotateFlip(RotateFlipType.RotateNoneFlipNone);
                        rotated = true;
                    }
                    break;
                case "1-->4":
                    //aanpassing in de x richting die altijd negatief is
                    while (tempX <= -1)
                    {
                        this.position.X--;
                        tempX++;
                    }
                    //aanpassing in de y richting die altijd negatief is
                    while (tempY <= -1)
                    {
                        position.Y--;
                        tempY++;
                    }
                    if (!rotated)
                    {
                        bitmap.RotateFlip(RotateFlipType.Rotate180FlipNone);
                        rotated = true;
                    }
                    break;

                case "2-->1":
                    //aanpassing in de x richting die altijd positief is
                    while (tempX >= 1)
                    {
                        this.position.X++;
                        tempX--;
                    }
                    //aanpassing in de y richting die altijd negatief is
                    while (tempY <= -1)
                    {
                        position.Y--;
                        tempY++;
                    }
                    if (!rotated)
                    {
                        bitmap.RotateFlip(RotateFlipType.Rotate270FlipNone);
                        rotated = true;
                    }
                    break;
                case "2-->2":
                    //aanpassing in de x richting die altijd positief is
                    while (tempX >= 1)
                    {
                        position.X++;
                        tempX--;
                    }
                    //aanpassing in de y richting die positief of negatief is
                    while (tempY >= 1)
                    {
                        this.position.Y++;
                        tempY--;
                    }
                    while (tempY <= -1)
                    {
                        this.position.Y--;
                        tempY++;
                    }
                    break;
                case "2-->3":
                    //aanpassing in de x richting die altijd positief is
                    while (tempX >= 1)
                    {
                        this.position.X++;
                        tempX--;
                    }
                    //aanpassing in de y richting die altijd positief is
                    while (tempY >= 1)
                    {
                        position.Y++;
                        tempY--;
                    }
                    if (!rotated)
                    {
                        bitmap.RotateFlip(RotateFlipType.RotateNoneFlipNone);
                        rotated = true;
                    }
                    break;

                case "3-->2":
                    //aanpassing in de x richting die altijd positief is
                    while (tempX >= 1)
                    {
                        this.position.X++;
                        tempX--;
                    }
                    //aanpassing in de y richting die altijd positief is
                    while (tempY >= 1)
                    {
                        position.Y++;
                        tempY--;
                    }
                    if (!rotated)
                    {
                        bitmap.RotateFlip(RotateFlipType.Rotate270FlipNone);
                        rotated = true;
                    }
                    break;
                case "3-->3":
                    //aanpassing in de x richting die positief of negatief is
                    while (tempX >= 1)
                    {
                        this.position.X++;
                        tempX--;
                    }
                    while (tempX <= -1)
                    {
                        this.position.X--;
                        tempX++;
                    }
                    //aanpassing in de y richting die altijd positief is
                    while (tempY >= 1)
                    {
                        position.Y++;
                        tempY--;
                    }
                    break;
                case "3-->4":
                    //aanpassing in de x richting die altijd negatief is
                    while (tempX <= -1)
                    {
                        this.position.X--;
                        tempX++;
                    }
                    //aanpassing in de y richting die altijd positief is
                    while (tempY >= 1)
                    {
                        position.Y++;
                        tempY--;
                    }
                    if (!rotated)
                    {
                        bitmap.RotateFlip(RotateFlipType.RotateNoneFlipNone);
                        rotated = true;
                    }
                    break;

                case "4-->1":
                    //aanpassing in de x richting die altijd negatief is
                    while (tempX <= -1)
                    {
                        this.position.X--;
                        tempX++;
                    }
                    //aanpassing in de y richting die altijd negatief is
                    while (tempY <= -1)
                    {
                        position.Y--;
                        tempY++;
                    }
                    if (!rotated)
                    {
                        bitmap.RotateFlip(RotateFlipType.Rotate90FlipNone);
                        rotated = true;
                    }
                    break;
                case "4-->4":
                    //aanpassing in de x richting die altijd negatief is
                    while (tempX <= -1)
                    {
                        this.position.X--;
                        tempX++;
                    }
                    //aanpassing in de y richting die positief of negatief is
                    while (tempY >= 1)
                    {
                        this.position.Y++;
                        tempY--;
                    }
                    while (tempY <= -1)
                    {
                        this.position.Y--;
                        tempY++;
                    }
                    break;
                case "4-->3":
                    //aanpassing in de x richting die altijd negatief is
                    while (tempX <= -1)
                    {
                        this.position.X--;
                        tempX++;
                    }
                    //aanpassing in de y richting die altijd positief is
                    while (tempY >= 1)
                    {
                        position.Y++;
                        tempY--;
                    }
                    if (!rotated)
                    {
                        bitmap.RotateFlip(RotateFlipType.Rotate270FlipNone);
                        rotated = true;
                    }
                    break;
            }
            updatePoint++;
        }