Esempio n. 1
0
 public Transition(TurnstileState start, TurnstileEvent e, TurnstileState end, Action a)
 {
     startState = start;
     trigger    = e;
     endState   = end;
     action     = a;
 }
        public void HandleEvent(TurnstileEvent e)
        {
            switch (state)
            {
            case TurnstileState.LOCKED:
                switch (e)
                {
                case TurnstileEvent.COIN:
                    state = TurnstileState.UNLOCKED;
                    turnstileController.Unlock();
                    break;

                case TurnstileEvent.PASS:
                    turnstileController.Alarm();
                    break;
                }
                break;

            case TurnstileState.UNLOCKED:
                switch (e)
                {
                case TurnstileEvent.COIN:
                    turnstileController.Thankyou();
                    break;

                case TurnstileEvent.PASS:
                    state = TurnstileState.LOCKED;
                    turnstileController.Lock();
                    break;
                }
                break;
            }
        }
Esempio n. 3
0
 public void HandleEvent(TurnstileEvent e)
 {
     foreach (var transition in transitions)
     {
         if (state == transition.startState && e == transition.trigger)
         {
             state = transition.endState;
             transition.action();
         }
     }
 }
Esempio n. 4
0
 private void AddTransition(TurnstileState start, TurnstileEvent e, TurnstileState end, Action action)
 {
     transitions.Add(new Transition(start, e, end, action));
 }
 public void SetUnlocked()
 {
     state = unlockedState;
 }
 public void SetLocked()
 {
     state = lockedState;
 }