public void GetNextTrafficLightSignal() { int randomLightSignal = rng.Next(4); switch (randomLightSignal) { case 0: signalLight = TrafficLightSignal.Green; break; case 1: signalLight = TrafficLightSignal.Yellow; break; case 2: signalLight = TrafficLightSignal.Red; break; case 3: signalLight = TrafficLightSignal.LeftTurnGreen; break; default: signalLight = TrafficLightSignal.Green; break; } }
public void SwitchLight() { int enumLength = Enum.GetNames(typeof(TrafficLightSignal)).Length; int currentIndex = (int)this.light; this.light = (TrafficLightSignal)((currentIndex + 1) % enumLength); }
public override string TurnVehicleLeft(TrafficLightSignal currentSignal) { if (currentSignal == TrafficLightSignal.LeftTurnGreen) { int result = CheckIfStoppedBeforeTurn(VehicleMovement.TurningLeft); if (result == 0) { return(VehicleName + " turned left."); } else { return(VehicleName + " can only move forward after stopping! Invalid input."); } } else { if (CurrentMovement == VehicleMovement.Stopped) { return(VehicleName + " can only move forward after stopping! Invalid input."); } else { return(VehicleName + " can only turn left on a Left Turn Green signal."); } } }
private static TrafficLightSignal SwitchLight(TrafficLightSignal trafficLight) { var enumLength = Enum.GetNames(typeof(TrafficLightSignal)).Length; var currentIndex = (int)trafficLight; trafficLight = (TrafficLightSignal)((currentIndex + 1) % enumLength); return(trafficLight); }
private static TrafficLightSignal SwitchTrafficLightSignal(TrafficLightSignal currentTrafficLightSignal) { var length = Enum.GetNames(typeof(TrafficLightSignal)).Length; var index = (int)currentTrafficLightSignal; currentTrafficLightSignal = (TrafficLightSignal)((index + 1) % length); return(currentTrafficLightSignal); }
public virtual string TurnVehicleLeft(TrafficLightSignal currentSignal) { if (currentSignal == TrafficLightSignal.LeftTurnGreen) { CurrentMovement = VehicleMovement.TurningLeft; return(VehicleName + " turned left."); } else { return(VehicleName + "can only turn left on a Left Turn Green signal."); } }
private IEnumerator RedSignal() { isSignalCoroutineEnd = false; SetPedestrianColliderStatus(false); VisualizeTrafficLightSignal(trafficLightLogic.TrafficLightSignal); delay = trafficLightLogic.CalculateDelay(levelData.levelNumber); Debug.Log($"{gameObject.name} : {trafficLightLogic.TrafficLightSignal} : {delay}s"); yield return(new WaitForSeconds(delay)); previousSignal = TrafficLightSignal.RedLight; trafficLightLogic.TrafficLightSignal = TrafficLightSignal.YellowLight; SetPedestrianColliderStatus(true); isSignalCoroutineEnd = true; }
public void UpdateTrafficLight() { switch (signalLight) { case TrafficLightSignal.Green: signalLight = TrafficLightSignal.Yellow; break; case TrafficLightSignal.Yellow: signalLight = TrafficLightSignal.Red; redLightCount = 0; break; case TrafficLightSignal.Red: bool willBeRed = rng.Next(2) == 1; if (redLightCount == 2) { signalLight = TrafficLightSignal.LeftTurnGreen; } else { if (willBeRed) { redLightCount++; } else { signalLight = TrafficLightSignal.LeftTurnGreen; } } break; case TrafficLightSignal.LeftTurnGreen: signalLight = TrafficLightSignal.Green; break; } }
/// <summary> /// Activates and deactivates necessary signal blockers on traffic light /// </summary> /// <param name="trafficLightSignal">Setted traffic light signal</param> private void VisualizeTrafficLightSignal(TrafficLightSignal trafficLightSignal) { switch (trafficLightSignal) { case TrafficLightSignal.RedLight: redLightBlocker.SetActive(false); yellowLightBlocker.SetActive(true); greenLightBlocker.SetActive(true); break; case TrafficLightSignal.YellowLight: redLightBlocker.SetActive(true); yellowLightBlocker.SetActive(false); greenLightBlocker.SetActive(true); break; case TrafficLightSignal.GreenLight: redLightBlocker.SetActive(true); yellowLightBlocker.SetActive(true); greenLightBlocker.SetActive(false); break; } }
public TrafficLight(string startLight) { this.light = (TrafficLightSignal)Enum.Parse(typeof(TrafficLightSignal), startLight); }