public SimpleGame(IBox box, SimpleGameOptions options) { this.Options = options; this.taskCompletionSource = new TaskCompletionSource <object>(); this.box = box; this.ledButtons = this.box.LedButtonPinPins.ToList().AsReadOnly(); this.stateMachine = new StateMachine <SimpleGameState, SimpleGameEvent>(SimpleGameState.Init); this.stateMachine.Configure(SimpleGameState.Init) .Permit(SimpleGameEvent.Start, SimpleGameState.Start); this.stateMachine.Configure(SimpleGameState.Start) .OnEntryAsync(this.InitializeChain) .Permit(SimpleGameEvent.DisplayChain, SimpleGameState.DisplayChain); this.stateMachine.Configure(SimpleGameState.DisplayChain) .OnEntryAsync(this.DoDisplayChain) .Permit(SimpleGameEvent.ChainDisplayed, SimpleGameState.AwaitInput); this.buttonPressedTrigger = this.stateMachine.SetTriggerParameters <ButtonIdentifier>(SimpleGameEvent.ButtonPressed); this.stateMachine.Configure(SimpleGameState.AwaitInput) .OnEntryFromAsync(SimpleGameEvent.ChainDisplayed, this.DoAwaitInput) .OnEntryFromAsync(this.buttonPressedTrigger, this.ButtonPressed) .PermitReentry(SimpleGameEvent.ButtonPressed) .Permit(SimpleGameEvent.ChainCorrectlyRepeated, SimpleGameState.Success) .Permit(SimpleGameEvent.ChainWronglyRepeated, SimpleGameState.Fault); this.stateMachine.Configure(SimpleGameState.Success) .OnEntryAsync(this.OnSuccess) .Permit(SimpleGameEvent.DisplayChain, SimpleGameState.DisplayChain) .Permit(SimpleGameEvent.Won, SimpleGameState.Won); this.stateMachine.Configure(SimpleGameState.Won) .OnEntryAsync(this.Won) .Permit(SimpleGameEvent.FinishChain, SimpleGameState.ChainFinished); this.stateMachine.Configure(SimpleGameState.Fault) .OnEntryAsync(this.OnFault) .Permit(SimpleGameEvent.DisplayChain, SimpleGameState.DisplayChain) .Permit(SimpleGameEvent.FinishChain, SimpleGameState.ChainFinished); this.stateMachine.Configure(SimpleGameState.ChainFinished) .OnEntryAsync(this.OnChainFinished) .Permit(SimpleGameEvent.DisplayChain, SimpleGameState.DisplayChain); }
public SimpleGameTimeSpanCalculator(SimpleGameOptions options, SimpleGameStatus status) { this.options = options; this.status = status; }