Exemplo n.º 1
0
        public TrafficLight()
        {
            InitializeComponent();
            CurrentPhase = TrafficPhase.Go;

            RedLight.SetState(LampState.Off);
            YellowLight.SetState(LampState.Off);
            GreenLight.SetState(LampState.On);
        }
Exemplo n.º 2
0
        static void EventTest()
        {
            RedLight redlight = new RedLight();
            Car      car      = new Car();
            Human    ming     = new Human();

            redlight.RedLightOnEvent += car.Stop;
            redlight.RedLightOnEvent += ming.Walk;
            redlight.On(EventArgs.Empty);
        }
Exemplo n.º 3
0
    public void EatRedLight(RedLight redLight)
    {
        this.accumulatorMan.redLights.Add(1);
        redLight.OnEat();

        for (int i = 0; i < reportOnRedLights.Count; i++)
        {
            if (this.reportOnRedLights[i] == this.accumulatorMan.redLights.AmountThisGame)
            {
                this.reportOnRedLights.RemoveAt(i);
                EventsMan.Instance.Call_OnTouchNRedLights(this.accumulatorMan.redLights.AmountThisGame);
            }
        }
    }
Exemplo n.º 4
0
    // Use this for initialization
    void Start()
    {
        Transform[] ts      = gameObject.GetComponentsInChildren <Transform> ();
        float       numRows = (float)(ts.Length - 1) / 2f;
        float       numSecsTotalSubtract = .5f;
        int         indexCount           = 0;

        foreach (Transform t in transform)
        {
            float    curRow = Mathf.Floor(indexCount / 2f);
            RedLight rL     = t.gameObject.GetComponent <RedLight> ();
            rL.setTimeSubtract(curRow / numRows * numSecsTotalSubtract);
            indexCount++;
        }
    }
Exemplo n.º 5
0
        int curLightIndex;                   //当前所亮的灯

        //public event LightChanged()  ;//事件



        private void UserControl_Resize()
        {
            // 变换灯的大小
            int w, h, d;

            w = this.Width;
            h = this.Height;
            d = w / 4;
            if (d > h)
            {
                d = h;
            }
            RedLight.Move(d / 4, (h - d) / 2, d, d);
            YellowLight.Move(d + d / 2, (h - d) / 2, d, d);
            GreenLight.Move(2 * d + 3 * d / 4, (h - d) / 2, d, d);
        }
Exemplo n.º 6
0
 private void OnTriggerEnter(Collider other)
 {
     if (other.CompareTag("RedLight"))
     {
         redLight = other.GetComponent <RedLight>();
         if (!redLight.canDrive)
         {
             AtRedLight();
         }
     }
     else
     {
         _crtSpeed = 0;
         _breaked  = true;
     }
 }
Exemplo n.º 7
0
        private async void ToggleLightsTask(Border control, int waitMillis)
        {
            void action()
            {
                if (GreenLight.Equals(control))
                {
                    ToggleGreen();
                }
                else if (RedLight.Equals(control))
                {
                    ToggleRed();
                }
            };

            for (int i = 0; i < 2; i++)
            {
                Dispatcher.Invoke(action);
                await Task.Delay(waitMillis).ConfigureAwait(false);
            }
        }
 private void Awake()
 {
     greenLight  = new GreenLight(this);
     yellowLight = new YellowLight(this);
     redLight    = new RedLight(this);
     foreach (Transform go in GetComponentsInChildren <Transform>())
     {
         if (go.name == "GreenLight")
         {
             greenLight.gLightBulb = go.gameObject;
         }
         if (go.name == "YellowLight")
         {
             yellowLight.yLightBulb = go.gameObject;
         }
         if (go.name == "RedLight")
         {
             redLight.rLightBulb = go.gameObject;
         }
     }
 }
Exemplo n.º 9
0
        private void LightTimer_Tick(object sender, EventArgs e)
        {
            //Attention phase
            if (CurrentPhase == TrafficPhase.Go)
            {
                CurrentPhase = TrafficPhase.Attention;
                RedLight.SetState(LampState.Off);
                YellowLight.SetState(LampState.On);
                GreenLight.SetState(LampState.Off);
                LightTimer.Interval = 3000;
            }
            //Stop phase
            else if (CurrentPhase == TrafficPhase.Attention)
            {
                CurrentPhase = TrafficPhase.Stop;
                RedLight.SetState(LampState.On);
                YellowLight.SetState(LampState.Off);//LightStateOff();
                GreenLight.SetState(LampState.Off);
                LightTimer.Interval = 6000;
            }
            //Prepare Phase

            else if (CurrentPhase == TrafficPhase.Stop)
            {
                CurrentPhase = TrafficPhase.Prepare;
                RedLight.SetState(LampState.On);
                YellowLight.SetState(LampState.On);
                GreenLight.SetState(LampState.Off);
                LightTimer.Interval = 2000;
            }
            else if (CurrentPhase == TrafficPhase.Prepare)
            {
                CurrentPhase = TrafficPhase.Go;
                RedLight.SetState(LampState.Off);
                YellowLight.SetState(LampState.Off);
                GreenLight.SetState(LampState.On);
                LightTimer.Stop();
            }
        }
Exemplo n.º 10
0
        public async void ToggleState()
        {
            if (TrafficTrafficState == TrafficState.STOP)
            {
                TrafficTrafficState = TrafficLight.TrafficState.READY;

                await Task.Delay(4000);

                TrafficTrafficState = TrafficLight.TrafficState.GO;
                RedLight.ToggleState();
                GreenLight.ToggleState();
                return;
            }

            TrafficTrafficState = TrafficState.READY;
            GreenLight.ToggleState();
            YellowLight.ToggleState();
            await Task.Delay(3000);

            TrafficTrafficState = TrafficState.STOP;
            YellowLight.ToggleState();
            RedLight.ToggleState();
        }
Exemplo n.º 11
0
        public new async Task ToggleState()
        {
            if (TrafficTrafficState == TrafficLight.TrafficState.STOP)
            {
                TrafficTrafficState = TrafficLight.TrafficState.READY;

                await Task.Delay(4000);

                TrafficTrafficState = TrafficLight.TrafficState.GO;
                RedLight.ToggleState();
                GreenLight.ToggleState();
                return;
            }

            TrafficTrafficState = TrafficLight.TrafficState.READY;
            GreenLight.ToggleState();
            await Blink(3000, 300, RedLight);

            TrafficTrafficState = TrafficState.STOP;
            if (!RedLight.IsActive)
            {
                RedLight.ToggleState();
            }
        }
Exemplo n.º 12
0
 public void AtGreenLight()
 {
     _breaked = false;
     redLight = null;
 }