Пример #1
0
 public GameStateAdvantage(TennisGame game, Party advantageParty)
     : base(game)
 {
     _advantageParty = advantageParty;
 }
Пример #2
0
 public abstract IGameState PointAdded(Party party);
Пример #3
0
 public int GetSetScore(Party party)
 {
     return _currentSet.GetSetScore(party);
 }
Пример #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);
            }
        }
Пример #5
0
 public ISetState GameAdded(Party party)
 {
     throw new InvalidOperationException("Games cannot be added to a won set.");
 }
Пример #6
0
        public void AddPoint(Party party)
        {
            if (GameOver)
                throw new InvalidOperationException("Cannot add points to won games.");

            IncreaseScore(party);
            _gameState = _gameState.PointAdded(party);
        }
Пример #7
0
 public abstract IMatchState SetAdded(Party party);
Пример #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;
        }
Пример #9
0
 public GameStateWon(TennisGame game, Party winningParty)
     : base(game)
 {
     _winningParty = winningParty;
 }
Пример #10
0
 public override IGameState PointAdded(Party party)
 {
     throw new InvalidOperationException("Cannot add points to a won game.");
 }
Пример #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;
        }
Пример #12
0
        public override IGameState PointAdded(Party party)
        {
            if (Game.GetScore(party) == 4)
                return new GameStateWon(Game, party);

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

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

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

            return ScoreB;
        }
Пример #26
0
 public int GetSetScore(Party party)
 {
     return GetScore(party);
 }
Пример #27
0
        public int GetScore(Party party)
        {
            if (party == PartyA)
            {
                return ScoreA;
            }

            return ScoreB;
        }
Пример #28
0
        public override IGameState PointAdded(Party party)
        {
            if (party == _advantageParty)
                return new GameStateWon(Game, _advantageParty);

            return new GameStateDeuce(Game);
        }
Пример #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;
        }