Пример #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();
        }
Пример #2
0
        public void Transition(string nextState)
        {
            if(currentState == null)
            {
                throw new NullReferenceException("no current state");
            }

            State next = currentState.Transitions[nextState];

            if(nextState == null)
            {
                throw new NullReferenceException("no state to transition to");
            }

            currentState.execLeave();
            previousState = currentState;
            currentState = next;
            currentState.execEnter();
        }
Пример #3
0
        /// <summary>
        /// update the state machine
        /// </summary>
        /// <param name="gameTime">the current game time</param>
        public void Update(GameTime gameTime)
        {
            // if there's no current state running, and we've somehow tried to update the state machine, throw an exception
            if (currentState == null)
            {
                throw new NullReferenceException("no start state");
            }

            // if we havent started yet, start!
            if (started == false)
            {
                currentState.execEnter();
                started = true;
            }

            //System.Diagnostics.Debug.WriteLine("current state: " + currentState.Name);

            // update the current state
            currentState.execUpdate(gameTime);
        }
Пример #4
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)
        {
            System.Diagnostics.Debug.WriteLine(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();
        }