// A collider has entered the front trigger public void TriggerEntered(Collider collider, TriggerType triggerType) { // Is something right in front of the vehicle? if (triggerType == TriggerType.Stop) { brakeHard = true; } // Was it a vehicle? if (collider.gameObject.transform.parent.gameObject.CompareTag(this.gameObject.tag)) { vehicleInFront = collider.gameObject.transform.parent.gameObject.GetComponent <VehicleController>(); } // Was it a stop light trigger? if (collider.CompareTag("StopTrigger")) { // Should the car really stop now? if (triggerType == TriggerType.Stop) { stopOnLight = true; //Debug.Log("I really should stop now"); } hitTrafficLightController = collider.transform.parent.gameObject.GetComponent <TrafficLightController>(); //Debug.Log("Hit a traffic light: " + hitTrafficLightController); } }
static void Main(string[] args) { Logger logger = LogManager.GetCurrentClassLogger(); CrossroadsView crossroadsView = new CrossroadsView(); crossroadsView.AddTrafficlight(new TrafficLightView(TrafficLightType.RoadATrafficLight, 19, 9, 19, 10, 19, 11)); crossroadsView.AddTrafficlight(new TrafficLightView(TrafficLightType.RoadATrafficLight, 40, 9, 40, 10, 40, 11)); crossroadsView.AddTrafficlight(new TrafficLightView(TrafficLightType.RoadBTrafficLight, 27, 7, 29, 7, 31, 7)); crossroadsView.AddTrafficlight(new TrafficLightView(TrafficLightType.RoadBTrafficLight, 27, 12, 29, 12, 31, 12)); crossroadsView.AddTrafficlight(new TrafficLightView(TrafficLightType.PedestrianTrafficLight, 18, 3, 18, 4)); crossroadsView.AddTrafficlight(new TrafficLightView(TrafficLightType.PedestrianTrafficLight, 40, 3, 40, 4)); crossroadsView.AddTrafficlight(new TrafficLightView(TrafficLightType.PedestrianTrafficLight, 18, 14, 18, 15)); crossroadsView.AddTrafficlight(new TrafficLightView(TrafficLightType.PedestrianTrafficLight, 40, 14, 40, 15)); crossroadsView.AddTrafficlight(new TrafficLightView(TrafficLightType.PedestrianTrafficLight, 7, 6, 9, 6)); crossroadsView.AddTrafficlight(new TrafficLightView(TrafficLightType.PedestrianTrafficLight, 7, 14, 9, 14)); crossroadsView.AddTrafficlight(new TrafficLightView(TrafficLightType.PedestrianTrafficLight, 49, 6, 51, 6)); crossroadsView.AddTrafficlight(new TrafficLightView(TrafficLightType.PedestrianTrafficLight, 49, 14, 51, 14)); TrafficLightController controller = new TrafficLightController(); Presenter presenter = new Presenter(crossroadsView, controller); crossroadsView.DrawCrossroads(); controller.StartWork(); crossroadsView.ControlPanel(); }
// A collider has exited the front trigger public void TriggerExited(Collider collider, TriggerType triggerType) { // Something exited right in front of the vehicle? if (triggerType == TriggerType.Stop) { brakeHard = true; } // Was it a vehicle? if (collider.gameObject.transform.parent.gameObject.CompareTag(this.gameObject.tag)) { if (vehicleInFront != null) { if (vehicleInFront.Equals(collider.gameObject.GetComponent <VehicleController>())) { vehicleInFront = null; } } } // Was it a trigger to stop? if (collider.CompareTag("StopTrigger")) { stopOnLight = false; hitTrafficLightController = null; } }
static async Task Main(string[] args) { TrafficLight trafficLight = new TrafficLight(4, 3, 2); TrafficLight trafficLight1 = new TrafficLight(18, 15, 14); TrafficLight trafficLight2 = new TrafficLight(22, 27, 17); TrafficLight trafficLight3 = new TrafficLight(11, 9, 10); Console.WriteLine("Welcome to traffic light controller"); using (var trafficLightController = new TrafficLightController(trafficLight3, TrafficPhase.RedPhase)) { trafficLightController.TrafficLightStatusMessageEvent += StatusMessageEvent; Console.WriteLine("Initial Staus:"); PrintStatus(trafficLightController); Console.WriteLine("Start task"); CancellationTokenSource tokenSource = new CancellationTokenSource(); var task = trafficLightController.StartTrafficLight(tokenSource.Token); Console.CancelKeyPress += (object sender, ConsoleCancelEventArgs args) => { tokenSource.Cancel(); task.Wait(); Console.WriteLine($"Task completed: {task.IsCompleted}"); Console.WriteLine("Bye"); }; Console.WriteLine($"Task completed: {task.IsCompleted}"); var result = await task; Console.WriteLine($"Result: {result}"); Console.ReadKey(); } Console.ReadKey(); }
public void CanIGo_given_Green_returns_True() { var ctrl = new TrafficLightController(); var go = ctrl.MayIGo(Green); Assert.True(go); }
public void CanIGo_given_Green_returns_True() { var controller = new TrafficLightController(); var go = controller.MayIGo("Green"); Assert.True(go); }
public void CanIGo_given_Red_returns_False() { var controller = new TrafficLightController(); var go = controller.MayIGo("RED"); Assert.False(go); }
public void Turning_on_lights(Light lightColor, string expectedOutputToUsbPort) { var portMock = Substitute.For<IUsbPort>(); var controller = new TrafficLightController(portMock); controller.TurnOn(lightColor); portMock.Received(1).Write(expectedOutputToUsbPort); }
public void CanIGo_given_Invalid_Color_throws_with_message_Invalid_Color() { var controller = new TrafficLightController(); var exception = Assert.Throws <ArgumentException>(() => controller.MayIGo("Invalid Color")); Assert.Equal("Invalid color", exception.Message); }
public void CanIGo_given_Yellow_returns_False() { var controller = new TrafficLightController(); var go = controller.MayIGo(TrafficLightColor.Yellow); Assert.False(go); }
public void MayIGo_given_color_returns_expected(TrafficLightColor color, bool expected) { var ctrl = new TrafficLightController(); var actual = ctrl.MayIGo(color); Assert.Equal(actual, expected); }
public void MayIGo_given_invalid_color_throws() { var ctrl = new TrafficLightController(); var actual = Assert.Throws <ArgumentException>(() => ctrl.MayIGo((TrafficLightColor)42)); Assert.Equal("Invalid color (Parameter 'color')", actual.Message); }
public void CanIGo_given_Red_returns_False() { var ctrl = new TrafficLightController(); var go = ctrl.MayIGo(Red); Assert.False(go); }
public void CanIGo_given_color_returns_expected(TrafficLightColor color, bool expected) { var controller = new TrafficLightController(); var go = controller.MayIGo(color); Assert.Equal(expected, go); }
// Update is called once per frame private void Update() { if (m_selectedTrafficLightController != null) { TrafficLightController m_tlc = m_selectedTrafficLightController; InfoPanelTextBox.text = "ID: " + m_tlc.GetInstanceID().ToString() + "/n"; InfoPanelTextBox.text += "testuy"; } }
void controlSpeed() { Vector3 posRayUp = new Vector3(transform.position.x, transform.position.y, transform.position.z); // Vector3 posRayUp = new Vector3(transform.position.x,transform.position.y); // Vector3 directRay = new Vector3(1,0,0); RaycastHit2D hitUp = Physics2D.Raycast(posRayUp, transform.up); // Debug.Log ("Transform up: " + transform.up); float dev = getDeviation(); if (transform.rotation.z > -0.23f) { //this.direction = 0; // Debug.Log ("Dev roration: " + dev); //dev = 0.6f; } if (dev == 1) { return; } this.speed = Mathf.Abs(Speed.clarify(1, 0f, 10f, dev)); int obj = 0; float disFob = 10; float df = 0; if (hitUp) { if (hitUp.collider.gameObject.tag == "TrafficLight") { TrafficLightController traffic = (TrafficLightController)hitUp.collider.gameObject.GetComponent <TrafficLightController> (); float dis = hitUp.distance; // Debug.Log ("Distance: "+dis); this.speed = Mathf.Abs(Speed.clarify(traffic.getIdL(), traffic.getRatioTime(), dis, dev)); obj = 0; //Debug.Log ("Distance: " + dis + " Time: " + traffic.getRatioTime() + " Deviation: " + dev); // Debug.Log ("Speed Controll: " + this.speed); } else if (hitUp.collider.gameObject.tag == "ForbiddenCar" && hitUp.distance < 2f) { df = hitUp.collider.gameObject.GetComponent <ForbiddenCar> ().getDeviation(); disFob = hitUp.distance; // this.speed = Mathf.Abs (Forbidden.clarify (hitUp.distance, df, 0)); obj = 1; Debug.Log("ForbiddenCar Distance: " + hitUp.distance); // Debug.Log ("ForbiddenCar Deviation: " + df); } } ; //Debug.Log ("Dev: " + dev); steer(dev, disFob, df, obj); }
public void ShouldStartTrafficLightCycle() { var configuration = new TrafficLightConfig(); configuration.Add(TrafficLightState.Go, 4); configuration.Add(TrafficLightState.Stop, 4); SetTrafficLightConfiguration(configuration); var lights = new TrafficLights { _l1, _l2, _l3, _l4 }; var timer = new TrafficLightTimer(); var tc1 = new TetheredTrafficLightCluster { _l1, _l2 }; tc1.Name = "TC-1"; var pc1 = new PolarTrafficLightCluster(_l3) { { _l4 } }; pc1.Name = "TC-2"; Assert.IsTrue(lights.Add(tc1)); Assert.IsTrue(lights.Add(pc1)); var controller = new TrafficLightController(lights, timer); //Assert initial state is where expected Assert.AreEqual(TrafficLightState.StopThenGo, _l1.State); Assert.AreEqual(TrafficLightState.StopThenGo, _l2.State); Assert.AreEqual(TrafficLightState.StopThenGo, _l3.State); Assert.AreEqual(TrafficLightState.StopThenGo, _l4.State); controller.Start(); //Will trigger traffic light state changes Thread.Sleep(2000); Assert.AreEqual(TrafficLightState.Go, _l1.State); Assert.AreEqual(TrafficLightState.Go, _l2.State); Assert.AreEqual(TrafficLightState.Go, _l3.State); Assert.AreEqual(TrafficLightState.Stop, _l4.State); Thread.Sleep(5000); Assert.AreEqual(TrafficLightState.Stop, _l1.State); Assert.AreEqual(TrafficLightState.Stop, _l2.State); Assert.AreEqual(TrafficLightState.Stop, _l3.State); Assert.AreEqual(TrafficLightState.Go, _l4.State); controller.Stop(); }
/// <summary> /// Sets up variables before scene is loaded /// </summary> void Awake() { GameObject go = GameObject.Find("CitySimulatorMap"); world = (WorldMap)go.GetComponent <WorldMap>(); go = GameObject.Find("TrafficLights"); trafficLightController = (TrafficLightController)go.GetComponent <TrafficLightController>(); sm = GameObject.Find("SessionManager").GetComponent <SessionManager>(); g = GameObject.Find("Graph").GetComponent <GraphController>().graph; pathList = new List <string>(); oneWays = new List <bool>(); }
public TrafficLightControllerTest() { trafficLightRepo = Mock.Of <ITrafficLightRepository>(); logger = Mock.Of <ILogger <TrafficLightController> >(); clewareLampControl = Mock.Of <IClewareLampControl>(); var hubContextMock = new Mock <IHubContext <TrafficLightHub> >(); clientProxy = Mock.Of <IClientProxy>(); hubContextMock.SetupGet(x => x.Clients.All).Returns(clientProxy); trafficLightController = new TrafficLightController( logger, trafficLightRepo, clewareLampControl, hubContextMock.Object); }
// Use this for initialization void Start() { DigitController [] digitControllers = this.GetComponentsInChildren <DigitController> (); if (digitControllers != null && digitControllers.Length == 2) { this.digit1 = digitControllers [0]; this.digit2 = digitControllers [1]; } else { Debug.LogWarning("Digits are missing"); } this.trafficLight = this.GetComponentInChildren <TrafficLightController> (); this.counter = this.timer; this.wall = this.GetComponent <BoxCollider> (); this.InvokeRepeating("DecreaseCounter", 1, 1); }
public void ShouldSynchronizedAllPolarLights() { var lights = new TrafficLights { _l1, _l2, _l3, _l4 }; var timer = new TrafficLightTimer(); var tc1 = new PolarTrafficLightCluster(_l3) { { _l1, _l2 } }; tc1.Name = "TC-1"; var tc2 = new PolarTrafficLightCluster(_l5) { { _l4 } }; tc2.Name = "TC-2"; Assert.IsTrue(lights.Add(tc1, tc2)); var controller = new TrafficLightController(lights, timer); //Assert initial state is where expected Assert.AreEqual(TrafficLightState.StopThenGo, _l1.State); Assert.AreEqual(TrafficLightState.StopThenGo, _l2.State); Assert.AreEqual(TrafficLightState.StopThenGo, _l3.State); Assert.AreEqual(TrafficLightState.StopThenGo, _l4.State); controller.Start(); //Will trigger traffic light state changes Thread.Sleep(2500); Assert.AreEqual(TrafficLightState.Go, _l3.State); Assert.AreEqual(TrafficLightState.Go, _l5.State); Assert.AreEqual(TrafficLightState.Stop, _l1.State); Assert.AreEqual(TrafficLightState.Stop, _l2.State); Assert.AreEqual(TrafficLightState.Stop, _l4.State); controller.Stop(); }
private void HandleTriggerEvent(Collider other) { // decide what to do depending on what we have collided with switch (other.transform.tag) { case "TrafficLight": // Debug.Log("Hit a traffic light.."); TrafficLightController theTLC = other.transform.GetComponent <TrafficLightController>(); RespondToTrafficLight(theTLC.GetTrafficLightStatus()); break; case "Vehicle": m_carStatus = CarStatus.Stopped; m_TargetSpeed = 0; break; default: break; } }
private void OnEnable() { _controller = (TrafficLightController)target; }
private void Start() { buttonColor1 = Pattern1.GetComponent <TrafficLightController>(); buttonColor2 = Pattern2.GetComponent <TrafficLightController>(); buttonColor3 = Pattern3.GetComponent <TrafficLightController>(); }
private static void PrintStatus(TrafficLightController controller) { Console.WriteLine($"Redsignal: {controller.TrafficLight.RedSignal.Status}"); Console.WriteLine($"Yellowsignal: {controller.TrafficLight.YellowSignal.Status}"); Console.WriteLine($"Greensignal: {controller.TrafficLight.GreenSignal.Status}"); }
public void CanIGo_given_Invalid_Color_throws_ArgumentException() { var controller = new TrafficLightController(); Assert.Throws <ArgumentException>(() => controller.MayIGo("Invalid Color")); }
public void CanIGo_given_42_throws_ArgumentException() { var controller = new TrafficLightController(); Assert.Throws <ArgumentException>(() => controller.MayIGo((TrafficLightColor)42)); }