/// <summary> /// Makes a car go straight when it gets out of the boundaries of the lane. /// </summary> /// <param name="lane">The lane that the car belongs to.</param> /// <param name="car">The car that will go straight.</param> public void GoStraightCar(LaneIn lane, Car car) { //Enters in the laneOut 'north' if (lane.Direction == "north") { if (!laneOutList[3].CarWithinBoundaries(car)) { car.Location = new Point(car.Location.X, car.Location.Y - 1); } else { laneOutList[3].CarList.Add(car); car.ToBeRemoved = true; } } // enters in the laneOut 'south' = laneOutList[2] else if (lane.Direction == "south") { if (!laneOutList[2].CarWithinBoundaries(car)) { car.Location = new Point(car.Location.X, car.Location.Y + 1); } else { laneOutList[2].CarList.Add(car); car.ToBeRemoved = true; } } // enters in the laneOut 'west' = laneOutList[1] else if (lane.Direction == "west") { if (!laneOutList[1].CarWithinBoundaries(car)) { car.Location = new Point(car.Location.X - 1, car.Location.Y); } else { laneOutList[1].CarList.Add(car); car.ToBeRemoved = true; } } // enters in the laneOut 'east' = laneOutList[0] else if (lane.Direction == "east") { if (!laneOutList[0].CarWithinBoundaries(car)) { car.Location = new Point(car.Location.X + 1, car.Location.Y); } else { laneOutList[0].CarList.Add(car); car.ToBeRemoved = true; } } }
/// <summary> /// Makes a car take a left turn when it gets out of the boundaries of the lane. /// </summary> /// <param name="lane">The lane that the car belongs to.</param> /// <param name="car">The car that will take the turn.</param> public void TurnLeftCar(LaneIn lane, Car car) { //laneIn with direction 'north' with left turn ends on LaneOut 'west' = laneOutList[1] if (lane.Direction == "north") { if (!laneOutList[1].CarWithinBoundaries(car)) { car.Location = new Point(car.Location.X - 1, car.Location.Y - 1); } else { laneOutList[1].CarList.Add(car); car.ToBeRemoved = true; } } //Entering in LaneOut "East" else if (lane.Direction == "south") { if (!laneOutList[0].CarWithinBoundaries(car)) { car.Location = new Point(car.Location.X + 1, car.Location.Y + 1); } else { laneOutList[0].CarList.Add(car); car.ToBeRemoved = true; } } else if (lane.Direction == "west") { //Entering in laneOut "South" if (!laneOutList[2].CarWithinBoundaries(car)) { car.Location = new Point(car.Location.X - 1, car.Location.Y + 1); } else { laneOutList[2].CarList.Add(car); car.ToBeRemoved = true; } } //Entering in laneout 'north' else if (lane.Direction == "east") { if (!laneOutList[3].CarWithinBoundaries(car)) { car.Location = new Point(car.Location.X + 1, car.Location.Y - 1); } else { laneOutList[3].CarList.Add(car); car.ToBeRemoved = true; } } }
public CrossingT2(Point location, PictureBox pb_background, PictureBox pb_transparrent) : base(location, pb_background, pb_transparrent) { //group 1 //from west Left TrafficLight tl1 = new TrafficLight(new Point(121, 147)); //from east Left TrafficLight tl2 = new TrafficLight(new Point(175, 147)); //from North StraightRIght TrafficLight tl3 = new TrafficLight(new Point(133, 119)); //from South StraightRight TrafficLight tl4 = new TrafficLight(new Point(164, 175)); //group 2 //from west StraightRight TrafficLight tl5 = new TrafficLight(new Point(121, 162)); //from east StraightRight TrafficLight tl6 = new TrafficLight(new Point(175, 132)); //From north Left TrafficLight tl7 = new TrafficLight(new Point(148, 119)); //from south Left TrafficLight tl8 = new TrafficLight(new Point(149, 175)); //Hardcode 12 lanes //To the Straight &right, checking Y for the stopPoint - 10pixels before the TL, Lenght - 10 LaneIn laneIn1 = new LaneIn(new Point(128, 0), 16, 127, "south", tl3, 110); //left LaneIn laneIn2 = new LaneIn(new Point(145, 0), 17, 127, "south", tl7, 110); //StopPoint - Location.Y + 10 //left LaneIn laneIn3 = new LaneIn(new Point(143, 172), 16, 133, "north", tl8, 185); //Straight & Right LaneIn laneIn4 = new LaneIn(new Point(158, 172), 17, 135, "north", tl4, 185); //StopPoint - Length- 10 //Left LaneIn laneIn5 = new LaneIn(new Point(0, 143), 127, 15, "east", tl1, 110); //Straight & Right LaneIn laneIn6 = new LaneIn(new Point(0, 158), 127, 15, "east", tl5, 110); //StopPoint - Location.X+10 //Straight & Right LaneIn laneIn7 = new LaneIn(new Point(173, 127), 135, 15, "west", tl6, 186); //Left LaneIn laneIn8 = new LaneIn(new Point(173, 144), 135, 15, "west", tl2, 186); this.LaneOutList.Add(new LaneOut(new Point(173, 159), 130, 14, "east", 295)); this.LaneOutList.Add(new LaneOut(new Point(0, 128), 128, 15, "west", 1)); this.LaneOutList.Add(new LaneOut(new Point(129, 173), 14, 127, "south", 292)); this.LaneOutList.Add(new LaneOut(new Point(160, 0), 14, 128, "north", 1)); //Adding LaneIn's to the LaneInList this.LaneInList.Add(laneIn1); this.LaneInList.Add(laneIn2); this.LaneInList.Add(laneIn3); this.LaneInList.Add(laneIn4); this.LaneInList.Add(laneIn5); this.LaneInList.Add(laneIn6); this.LaneInList.Add(laneIn7); this.LaneInList.Add(laneIn8); //Adding to the groups Groups.AddToGroup1(tl1); Groups.AddToGroup1(tl2); Groups.AddToGroup2(tl3); Groups.AddToGroup2(tl4); Groups.AddToGroup3(tl5); Groups.AddToGroup3(tl6); Groups.AddToGroup4(tl7); Groups.AddToGroup4(tl8); //sets grp1 to green Groups.SetLight(Groups.GetGroup1(), true); //Setting the LaneIn to the traffic lights tl1.LaneIn = laneIn5; tl2.LaneIn = laneIn8; tl3.LaneIn = laneIn1; tl4.LaneIn = laneIn4; tl5.LaneIn = laneIn6; tl6.LaneIn = laneIn7; tl7.LaneIn = laneIn2; tl8.LaneIn = laneIn3; }
public CrossingT1(Point location, PictureBox pb_background, PictureBox pb_transparrent) : base(location, pb_background, pb_transparrent) { //group 1 TrafficLight tl1 = new TrafficLight(new Point(122, 161)); TrafficLight tl2 = new TrafficLight(new Point(175, 131)); //group 2 TrafficLight tl3 = new TrafficLight(new Point(122, 147)); TrafficLight tl4 = new TrafficLight(new Point(175, 146)); //group 3 TrafficLight tl5 = new TrafficLight(new Point(161, 175)); TrafficLight tl6 = new TrafficLight(new Point(137, 118)); //StopPoint - Length - 10 //Left LaneIn laneIn1 = new LaneIn(new Point(0, 144), 127, 15, "east", tl3, 110); //Right and straight LaneIn laneIn2 = new LaneIn(new Point(0, 159), 127, 15, "east", tl1, 110); //StopPoint - Location.X + 10 //Left LaneIn laneIn3 = new LaneIn(new Point(173, 128), 135, 15, "west", tl2, 186); //Right and straight LaneIn laneIn4 = new LaneIn(new Point(173, 142), 135, 15, "west", tl4, 186); //Lenght - 30 //ONLY Straight LaneIn laneIn5 = new LaneIn(new Point(128, 0), 24, 127, "south", tl6, 93); //Location.Y + 30 //Only Straight LaneIn laneIn6 = new LaneIn(new Point(151, 173), 25, 127, "north", tl5, 203); this.LaneOutList.Add(new LaneOut(new Point(177, 157), 123, 16, "east", 295)); this.LaneOutList.Add(new LaneOut(new Point(0, 128), 128, 15, "west", 1)); this.LaneOutList.Add(new LaneOut(new Point(129, 173), 22, 128, "south", 292)); this.LaneOutList.Add(new LaneOut(new Point(152, 0), 22, 127, "north", 1)); //Adding LaneIn's in the LaneInList this.LaneInList.Add(laneIn1); this.LaneInList.Add(laneIn2); this.LaneInList.Add(laneIn3); this.LaneInList.Add(laneIn4); this.LaneInList.Add(laneIn5); this.LaneInList.Add(laneIn6); //adding groups Groups.AddToGroup1(tl1); Groups.AddToGroup1(tl2); Groups.AddToGroup2(tl3); Groups.AddToGroup2(tl4); Groups.AddToGroup3(tl5); Groups.AddToGroup3(tl6); //sets grp1 to green Groups.SetLight(Groups.GetGroup1(), true); //Setting the laneIn to the traffic lights tl1.LaneIn = laneIn2; tl2.LaneIn = laneIn3; tl3.LaneIn = laneIn1; tl4.LaneIn = laneIn4; tl5.LaneIn = laneIn6; tl6.LaneIn = laneIn5; }
/// <summary> /// Makes a car take a right turn when it gets out of the boundaries of the lane. /// </summary> /// <param name="lane">The lane that the car belongs to.</param> /// <param name="car">The car that will take the turn.</param> public void TurnRightCar(LaneIn lane, Car car) { //laneIn with direction 'north' with right turn ends on LaneOut 'east' (equal laneOutList[0] if (lane.Direction == "north") { //while the car is not yet in the boundary of laneOut, turn should be turning if (!laneOutList[0].CarWithinBoundaries(car)) { car.Location = new Point(car.Location.X + 1, car.Location.Y - 1); } //when the car enters in the boundary of the LaneOut, add it in the laneOut and remove it from the laneIn else { laneOutList[0].CarList.Add(car); car.ToBeRemoved = true; } } //laneIn with direction 'south' with right turn ends on LaneOut 'west' = laneOutList[1] else if (lane.Direction == "south") { //turn right while car is not in the laneOut yet if (!laneOutList[1].CarWithinBoundaries(car)) { car.Location = new Point(car.Location.X - 1, car.Location.Y + 1); } else { laneOutList[1].CarList.Add(car); car.ToBeRemoved = true; } } //laneIn with direction 'west' with right turn ends on LaneOut 'north' = laneOutList[3] else if (lane.Direction == "west") { if (!laneOutList[3].CarWithinBoundaries(car)) { car.Location = new Point(car.Location.X - 1, car.Location.Y - 1); } else { laneOutList[3].CarList.Add(car); car.ToBeRemoved = true; } } //laneIn with direction 'east' with right turn ends on LaneOut 'south' = laneOutList[2] else if (lane.Direction == "east") { if (!laneOutList[2].CarWithinBoundaries(car)) { car.Location = new Point(car.Location.X + 1, car.Location.Y + 1); } else { laneOutList[2].CarList.Add(car); car.ToBeRemoved = true; } } }