コード例 #1
0
 public Tournament(
     TournamentState currentState,
     TournamentRules rules,
     IEnumerable <Guid> contestants)
 {
     _state            = new BehaviorSubject <TournamentState>(currentState);
     _rules            = rules;
     _contestantsGuids = contestants.ToArray();
 }
コード例 #2
0
 public Tournament()
 {
     _rules            = new TournamentRules();
     _state            = new BehaviorSubject <TournamentState>(TournamentState.Created());
     _contestantsGuids = new Guid[_rules.MaxContestantsCount()];
     _machine          = new StateMachine <TournamentState, Trigger>(() => _state.Value,
                                                                     newState => _state.OnNext(newState));
     _machine.Configure(TournamentState.Created())
     .Permit(Trigger.StartTournament, TournamentState.TournamentInProgress.FirstWave());
     _machine.Configure(TournamentState.TournamentInProgress.FirstWave())
     .Permit(Trigger.Cancel, TournamentState.Cancelled())
     .Permit(Trigger.MoveToNextWave, TournamentState.TournamentInProgress.SecondWave());
     _machine.Configure(TournamentState.TournamentInProgress.SecondWave())
     .Permit(Trigger.Cancel, TournamentState.Cancelled())
     .Permit(Trigger.MoveToNextWave, TournamentState.TournamentInProgress.SemiFinal());
     _machine.Configure(TournamentState.TournamentInProgress.SemiFinal())
     .Permit(Trigger.Cancel, TournamentState.Cancelled())
     .Permit(Trigger.MoveToNextWave, TournamentState.TournamentInProgress.Final());
     _machine.Configure(TournamentState.TournamentInProgress.Final())
     .Permit(Trigger.Cancel, TournamentState.Cancelled())
     .Permit(Trigger.Finish, TournamentState.Finished());
 }