public GameStateAdvantage(TennisGame game, Party advantageParty) : base(game) { _advantageParty = advantageParty; }
public abstract IGameState PointAdded(Party party);
public int GetSetScore(Party party) { return _currentSet.GetSetScore(party); }
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); } }
public ISetState GameAdded(Party party) { throw new InvalidOperationException("Games cannot be added to a won set."); }
public void AddPoint(Party party) { if (GameOver) throw new InvalidOperationException("Cannot add points to won games."); IncreaseScore(party); _gameState = _gameState.PointAdded(party); }
public abstract IMatchState SetAdded(Party party);
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; }
public GameStateWon(TennisGame game, Party winningParty) : base(game) { _winningParty = winningParty; }
public override IGameState PointAdded(Party party) { throw new InvalidOperationException("Cannot add points to a won game."); }
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; }
public override IGameState PointAdded(Party party) { if (Game.GetScore(party) == 4) return new GameStateWon(Game, party); return this; }
public override IGameState PointAdded(Party party) { return new GameStateAdvantage(Game, party); }
public int IncreaseScore(Party party) { if (party == PartyA) { ScoreA += 1; return ScoreA; } ScoreB += 1; return ScoreB; }
public override IMatchState SetAdded(Party party) { if (Match.GetScore(party) >= 3) return new MatchStateWon(Match, party); return this; }
public abstract ISetState GameAdded(Party party);
public MatchStateWon(TennisMatch match, Party winningParty) : base(match) { _winningParty = winningParty; }
public SetStateWon(TennisSet set, Party winningParty) { _set = set; _winningParty = winningParty; }
public override IMatchState SetAdded(Party party) { throw new InvalidOperationException("Sets cannot be added to a won match."); }
public TennisGame(Party partyA, Party partyB, Func<TennisGame, IGameState> gameStateFactory) : base(partyA, partyB) { _gameState = gameStateFactory(this); }
public ScoringContext(Party partyA, Party partyB) { PartyA = partyA; PartyB = partyB; }
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 ScoringContext(Party partyA, Party partyB, int scoreA, int scoreB) { PartyA = partyA; PartyB = partyB; ScoreA = scoreA; ScoreB = scoreB; }
public TennisSet(ITournamentRules tournamentRules, Party partyA, Party partyB, Func<TennisSet, ISetState> setStateFactory) : base(partyA, partyB) { _setState = setStateFactory(this); _tournamentRules = tournamentRules; _currentGame = _setState.GetNextGame(tournamentRules); }
public int GetOpposingScore(Party party) { if (party == PartyB) { return ScoreA; } return ScoreB; }
public int GetSetScore(Party party) { return GetScore(party); }
public int GetScore(Party party) { if (party == PartyA) { return ScoreA; } return ScoreB; }
public override IGameState PointAdded(Party party) { if (party == _advantageParty) return new GameStateWon(Game, _advantageParty); return new GameStateDeuce(Game); }
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; }