Пример #1
0
        public bool RemoveState(State state)
        {
            if (!ContainState(state))
            {
                Console.WriteLine("状态“" + state.GetName() + "”不存在!");

                return(false);
            }

            if (currentState.GetId() == state.GetId())
            {
                Console.WriteLine("状态“" + state.GetName() + "”是当前状态,无法删除!");

                return(false);
            }

            return(stateList.Remove(state));
        }
Пример #2
0
        public void SetCurrentState(State state)
        {
            if (!ContainState(state))
            {
                Console.WriteLine("状态“" + state.GetName() + "”不存在!");

                return;
            }

            currentState = state;
        }
Пример #3
0
        public void AddState(State state)
        {
            if (ContainState(state))
            {
                Console.WriteLine("状态“" + state.GetName() + "”已存在!");

                return;
            }

            stateList.Add(state);
        }
Пример #4
0
        public void CheckAndChangeState()
        {
            Transition transition = currentState.GetEnabledTransition();

            if (transition != null)
            {
                Console.Write("由“" + currentState.GetName() + "”状态");

                currentState = transition.GetEnd();

                Console.WriteLine("到“" + currentState.GetName() + "”状态。");

                if (currentState.GetId() == startState.GetId())
                {
                    RestoreAllStates();
                }
            }
            else
            {
                currentState.DoAction();
            }
        }