public TennisMatch(ITournamentRules tournamentRules, Func <TennisMatch, IMatchState> matchStateFactory)
     : base(new Party("A"), new Party("B"))
 {
     _tournamentRules = tournamentRules;
     _matchState      = matchStateFactory(this);
     _currentSet      = _matchState.GetNextSet(tournamentRules);
 }
        public void AddPoint(Party party)
        {
            if (_matchState.MatchOver)
            {
                throw new InvalidOperationException("Cannot add points to won matches.");
            }

            _currentSet.AddPoint(party);

            if (_currentSet.SetOver)
            {
                IncreaseScore(party);
                _matchState = _matchState.SetAdded(party);

                if (!_matchState.MatchOver)
                {
                    _currentSet = _matchState.GetNextSet(_tournamentRules);
                }
            }
        }
 public ISetState GetDecidingSetState(TennisSet set)
 {
     return(new SetStateAdvantageScoring(set));
 }
 public ISetState GetStandardSetState(TennisSet set)
 {
     return(new SetStateTieBreakScoring(set));
 }
 public SetStateWon(TennisSet set, Party winningParty)
 {
     _set          = set;
     _winningParty = winningParty;
 }
 public SetStateTieBreakScoring(TennisSet set)
     : base(set)
 {
 }
 protected SetStateBase(TennisSet set)
 {
     Set = set;
 }
 public SetStateAdvantageScoring(TennisSet set)
     : base(set)
 {
 }
 public ISetState GetDecidingSetState(TennisSet set)
 {
     return(new SetStateTieBreakScoring(set));
 }