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);
                }
            }
        }
Example #3
0
        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);
            }
        }
Example #4
0
 public TennisMatch(ITournamentRules tournamentRules, Func<TennisMatch, IMatchState> matchStateFactory)
     : base(new Party("A"), new Party("B"))
 {
     _tournamentRules = tournamentRules;
     _matchState = matchStateFactory(this);
     _currentSet = _matchState.GetNextSet(tournamentRules);
 }