Exemple #1
0
        public bool PerformTransition(GameStateTransitionType transition)
        {
            Debug.Log("CallingThetransition");
            Debug.Log("Transition is: " + transition);
            GameStateType targetStateType =
                CurrentState.GetTargetStateType(transition);

            Debug.Log("targetStateType is: " + targetStateType);
            if (targetStateType == GameStateType.Error)
            {
                return(false);
            }

            foreach (var state in _states)
            {
                if (state.State == targetStateType)
                {
                    CurrentState.StateDeactivating();
                    CurrentState = state;
                    CurrentState.StateActivated();

                    return(true);
                }
            }

            return(false);
        }
 public GameStateType GetTargetStateType(GameStateTransitionType transition)
 {
     if (Transitions.ContainsKey(transition))
     {
         return(Transitions[transition]);
     }
     return(GameStateType.Error);
 }
        public bool AddTransition(GameStateTransitionType transition,
                                  GameStateType targetState)
        {
            if (transition == GameStateTransitionType.Error ||
                targetState == GameStateType.Error ||
                Transitions.ContainsKey(transition))
            {
                // We cannot add a transition to our dictionary more than once.
                // Otherwise we wouldn't know to which state we should go with
                // that transition.
                return(false);
            }

            Transitions.Add(transition, targetState);
            return(true);
        }
Exemple #4
0
        public bool PerformTransition(GameStateTransitionType transition)
        {
            GameStateType targetStateType =
                CurrentState.GetTargetStateType(transition);

            if (targetStateType == GameStateType.Error)
            {
                return(false);
            }

            foreach (var state in _states)
            {
                if (state.State == targetStateType)
                {
                    CurrentState.StateDeactivating();
                    CurrentState = state;
                    CurrentState.StateActivated();

                    return(true);
                }
            }

            return(false);
        }
 public bool RemoveTransition(GameStateTransitionType transition)
 {
     return(Transitions.Remove(transition));
 }