Example #1
0
 public GameStateAdvantage(TennisGame game, Party advantageParty)
     : base(game)
 {
     _advantageParty = advantageParty;
 }
Example #2
0
 public abstract IGameState PointAdded(Party party);
Example #3
0
 public int GetSetScore(Party party)
 {
     return _currentSet.GetSetScore(party);
 }
Example #4
0
        public void AddPoint(Party party)
        {
            if (SetOver)
                throw new InvalidOperationException("Cannot add points to won sets.");

            _currentGame.AddPoint(party);

            if (_currentGame.GameOver)
            {
                IncreaseScore(party);
                _setState = _setState.GameAdded(party);

                if (!_setState.SetOver)
                    _currentGame = _setState.GetNextGame(_tournamentRules);
            }
        }
Example #5
0
 public ISetState GameAdded(Party party)
 {
     throw new InvalidOperationException("Games cannot be added to a won set.");
 }
Example #6
0
        public void AddPoint(Party party)
        {
            if (GameOver)
                throw new InvalidOperationException("Cannot add points to won games.");

            IncreaseScore(party);
            _gameState = _gameState.PointAdded(party);
        }
Example #7
0
 public abstract IMatchState SetAdded(Party party);
Example #8
0
        public override ISetState GameAdded(Party party)
        {
            int score = Set.GetScore(party);
            int opposingScore = Set.GetOpposingScore(party);

            if (score > 6)
                return new SetStateWon(Set, party);

            if (ScoreHelper.IsAboveWithMargin(score, opposingScore, 6, 2))
                return new SetStateWon(Set, party);

            return this;
        }
Example #9
0
 public GameStateWon(TennisGame game, Party winningParty)
     : base(game)
 {
     _winningParty = winningParty;
 }
Example #10
0
 public override IGameState PointAdded(Party party)
 {
     throw new InvalidOperationException("Cannot add points to a won game.");
 }
Example #11
0
        public override IGameState PointAdded(Party party)
        {
            int newScore = Game.GetScore(party);
            int oppScore = Game.GetOpposingScore(party);

            if (ScoreHelper.IsAboveWithMargin(newScore, oppScore, 7, 2))
                return new GameStateWon(Game, party);

            return this;
        }
Example #12
0
        public override IGameState PointAdded(Party party)
        {
            if (Game.GetScore(party) == 4)
                return new GameStateWon(Game, party);

            return this;
        }
Example #13
0
 public override IGameState PointAdded(Party party)
 {
     return new GameStateAdvantage(Game, party);
 }
Example #14
0
        public int IncreaseScore(Party party)
        {
            if (party == PartyA)
            {
                ScoreA += 1;
                return ScoreA;
            }

            ScoreB += 1;
            return ScoreB;
        }
Example #15
0
        public override IMatchState SetAdded(Party party)
        {
            if (Match.GetScore(party) >= 3)
                return new MatchStateWon(Match, party);

            return this;
        }
Example #16
0
 public abstract ISetState GameAdded(Party party);
Example #17
0
 public MatchStateWon(TennisMatch match, Party winningParty)
     : base(match)
 {
     _winningParty = winningParty;
 }
Example #18
0
 public SetStateWon(TennisSet set, Party winningParty)
 {
     _set = set;
     _winningParty = winningParty;
 }
Example #19
0
 public override IMatchState SetAdded(Party party)
 {
     throw new InvalidOperationException("Sets cannot be added to a won match.");
 }
Example #20
0
 public TennisGame(Party partyA, Party partyB, Func<TennisGame, IGameState> gameStateFactory)
     : base(partyA, partyB)
 {
     _gameState = gameStateFactory(this);
 }
Example #21
0
 public ScoringContext(Party partyA, Party partyB)
 {
     PartyA = partyA;
     PartyB = partyB;
 }
Example #22
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 #23
0
 public ScoringContext(Party partyA, Party partyB, int scoreA, int scoreB)
 {
     PartyA = partyA;
     PartyB = partyB;
     ScoreA = scoreA;
     ScoreB = scoreB;
 }
Example #24
0
 public TennisSet(ITournamentRules tournamentRules, Party partyA, Party partyB, Func<TennisSet, ISetState> setStateFactory)
     : base(partyA, partyB)
 {
     _setState = setStateFactory(this);
     _tournamentRules = tournamentRules;
     _currentGame = _setState.GetNextGame(tournamentRules);
 }
Example #25
0
        public int GetOpposingScore(Party party)
        {
            if (party == PartyB)
            {
                return ScoreA;
            }

            return ScoreB;
        }
Example #26
0
 public int GetSetScore(Party party)
 {
     return GetScore(party);
 }
Example #27
0
        public int GetScore(Party party)
        {
            if (party == PartyA)
            {
                return ScoreA;
            }

            return ScoreB;
        }
Example #28
0
        public override IGameState PointAdded(Party party)
        {
            if (party == _advantageParty)
                return new GameStateWon(Game, _advantageParty);

            return new GameStateDeuce(Game);
        }
Example #29
0
        public override IGameState PointAdded(Party party)
        {
            if (Game.GetScore(party) == 3 && Game.GetOpposingScore(party) == 3)
                return new GameStateDeuce(Game);

            if (Game.GetScore(party) == 4)
                return new GameStateWon(Game, party);

            return this;
        }