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 SetCurrentState(State state) { if (!ContainState(state)) { Console.WriteLine("状态“" + state.GetName() + "”不存在!"); return; } currentState = state; }
public void AddState(State state) { if (ContainState(state)) { Console.WriteLine("状态“" + state.GetName() + "”已存在!"); return; } stateList.Add(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(); } }