public void Setup() { canPlay = true; stateMachine = new StateMachine(StateCollection.FromEnum <States>(), InputCollection.FromEnum <Input>(), new DictionaryStateTransitionTable(), States.Begin.ToString()); stateMachine.Define(new BinaryTransition(States.Begin.ToString(), Input.Play.ToString(), States.Playing.ToString(), States.End.ToString(), () => { if (canPlay) { return(new BinaryTransitionResult(BinaryChoice.Left, "Started Playing")); } else { return(new BinaryTransitionResult(BinaryChoice.Right, "Could not start playing")); } }, "Start Playing")); stateMachine.Define(new InvalidTransition(States.Begin.ToString(), Input.Pause.ToString(), "Must be Playing to Pause")); stateMachine.Define(new UnaryTransition(States.Begin.ToString(), Input.Stop.ToString(), States.End.ToString(), () => { return(new UnaryTransitionResult("Stopped")); }, "Stop before playing")); stateMachine.Define(new UnaryTransition(States.Playing.ToString(), Input.Play.ToString(), States.Playing.ToString(), () => { return(new UnaryTransitionResult("Kept playing")); }, "Already Playing")); stateMachine.Define(new UnaryTransition(States.Playing.ToString(), Input.Pause.ToString(), States.Paused.ToString(), () => { return(new UnaryTransitionResult("Paused playback")); }, "Already Playing")); stateMachine.Define(new UnaryTransition(States.Playing.ToString(), Input.Stop.ToString(), States.End.ToString(), () => { return(new UnaryTransitionResult("Stopped")); }, "Stopped")); stateMachine.Define(new BinaryTransition(States.Paused.ToString(), Input.Play.ToString(), States.Playing.ToString(), States.End.ToString(), () => { if (canPlay) { return(new BinaryTransitionResult(BinaryChoice.Left, "Resumed Playback")); } else { return(new BinaryTransitionResult(BinaryChoice.Right, "Could not Resumed Playback")); } }, "Resume Playback")); stateMachine.Define(new UnaryTransition(States.Paused.ToString(), Input.Pause.ToString(), States.Paused.ToString(), () => { return(new UnaryTransitionResult("Already Paused")); }, "Already Paused")); stateMachine.Define(new UnaryTransition(States.Paused.ToString(), Input.Stop.ToString(), States.End.ToString(), () => { return(new UnaryTransitionResult("Stopped")); }, "Stopped")); stateMachine.Define(new InvalidTransition(States.End.ToString(), Input.Play.ToString(), "Cannot play from end state")); stateMachine.Define(new InvalidTransition(States.End.ToString(), Input.Pause.ToString(), "Cannot pause from end state")); stateMachine.Define(new InvalidTransition(States.End.ToString(), Input.Stop.ToString(), "Cannot stop from end state")); }