예제 #1
0
 public Transition(eTurnstileState start_state,
                   eTurnstileState end_state,
                   eTurnstileEvent event_trigger,
                   Action action)
 {
     StartState   = start_state;
     EndState     = end_state;
     EventTrigger = event_trigger;
     Action       = action;
 }
예제 #2
0
 /// <summary>
 /// 状态事件解释引擎
 /// </summary>
 /// <param name="e"></param>
 public void HandleEvent(eTurnstileEvent e)
 {
     foreach (var transition in _transitions)
     {
         if (State == transition.StartState &&
             e == transition.EventTrigger)
         {
             transition.Action();
             State = transition.EndState;
         }
     }
 }
예제 #3
0
        public Turnstile(ITurnstileController controller)
        {
            // 构建状态迁移表
            Action unlock      = controller.Unlock;
            Action alarm       = controller.Alarm;
            Action thankyou    = controller.Thankyou;
            Action lock_action = controller.Lock;

            AddTransition(eTurnstileState.Locked, eTurnstileState.Unlocked, eTurnstileEvent.Coin, unlock);
            AddTransition(eTurnstileState.Locked, eTurnstileState.Locked, eTurnstileEvent.Pass, alarm);
            AddTransition(eTurnstileState.Unlocked, eTurnstileState.Unlocked, eTurnstileEvent.Coin, thankyou);
            AddTransition(eTurnstileState.Unlocked, eTurnstileState.Locked, eTurnstileEvent.Pass, lock_action);

            State = eTurnstileState.Locked;
        }
예제 #4
0
 private void AddTransition(eTurnstileState start, eTurnstileState end,
                            eTurnstileEvent e, Action action)
 {
     _transitions.Add(new Transition(start, end, e, action));
 }