public bool ContainState(State state) { foreach (State s in stateList) { if (s.GetId() == state.GetId()) { return(true); } } return(false); }
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)); }
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(); } }