示例#1
0
        /// <summary>
        /// transition to the next state in execution
        /// </summary>
        /// <param name="nextState">the name of the state to transition to</param>
        public void Transition(string nextState)
        {
            // if there's no current state running, and we've somehow tried to  transition, throw an exception
            if (currentState == null)
            {
                throw new NullReferenceException("no current state");
            }

            // get the next state from the current state's list of transitions
            State next = currentState.Transitions[nextState];

            // if no state was returned, then the current state cannot transition to that state
            if (nextState == null)
            {
                throw new NullReferenceException("no state to transition to");
            }

            // leave the current state
            currentState.execLeave();
            // set the state objects correctly
            previousState = currentState;
            currentState  = next;
            // enter the (new) current state
            currentState.execEnter();
        }