private void HandleBonusRoll(int score, IGameCalculator gameCalculator, Guid currentGameId) { Logger.Info("BowlingPlayer :: HandleBonusRoll"); if (CurrentFrame.BonusScore == null) { CurrentFrame.BonusScore = new List <IRollScore> { new RollScore(score) } } ; else { CurrentFrame.BonusScore.Add(new RollScore(score)); } gameCalculator.CalculateScore(score, _currentFrameCounter, Frames); if (CurrentFrame.IsStrike) { HandleStrikeBonus(currentGameId); } else { HandleFrameEntity(currentGameId); } }
private void HandleFullFrame(Guid currentGameId, IGameCalculator gameCalculator, int score) { if (CurrentFrame.IsFull(_gameRules.NumberOfRolls)) { gameCalculator.CalculateScore(score, _currentFrameCounter, Frames); HandleFrameEntity(currentGameId); NextPlayerRollEvent(); } else { RunAdditionalRollEvent(); } }
public Game(IPlayers players, IGameCalculator gameCalculator, IGameRules gameRules, IGameEntity gamEntity) { Players = players; GameCalculator = gameCalculator; GameCalculator.GameId = Id; GameRules = gameRules; GamEntity = gamEntity; Id = Guid.NewGuid(); players.CurrentGameIdGuid = Id; gameCalculator.GameId = Id; }
public void Play(int score, IGameCalculator gameCalculator, int currentFrameCounter, RollResults rollResult, Guid currentGameId) { Logger.Info("BowlingPlayer :: Play"); _currentFrameCounter = currentFrameCounter; ValidateData(score, rollResult); try { if (rollResult == RollResults.Bonus) { HandleBonusRoll(score, gameCalculator, currentGameId); return; } if (ShouldCreateFrame()) { Frames.Add(new Frame(_currentFrameCounter)); } CurrentFrame = Frames[_currentFrameCounter]; if (HandleStrikeFrame(currentGameId, gameCalculator, score)) { return; } CurrentFrame.RollScore.Add(new RollScore(score)); if (HandleSpareFrame(currentFrameCounter)) { return; } HandleFullFrame(currentGameId, gameCalculator, score); } catch (Exception e) { Logger.Error(e); throw e; } }
public BowlingGame( IPlayers players, IGameCalculator gameCalculator, IGameRules gameRules, IGameEntity bowlingGamEntity, IMessageFactory messageFactory, IPlayerFactory playerFactory) : base(players, gameCalculator, gameRules, bowlingGamEntity) { MessageFactory = messageFactory; PlayerFactory = playerFactory; bowlingGamEntity.Insert("Bowling", DateTime.Now, Guid.NewGuid()); _bowlingGameRules = gameRules as BowlingGameRules; Logger.Info("BowlingGame :: Create a new Game"); }
private bool HandleStrikeFrame(Guid currentGameId, IGameCalculator gameCalculator, int score) { if (!_gameRules.IsStrike(score, CurrentFrame)) { return(false); } RunBonusMessageEvent(); CurrentFrame.IsStrike = true; CurrentFrame.RollScore.Add(new RollScore(score)); CurrentFrame.RollScore.Add(new RollScore(0)); gameCalculator.CalculateScore(score, _currentFrameCounter, Frames); HandleFrameEntity(currentGameId); NextPlayerRollEvent(); return(true); }
public BowlingController(IGameCalculator gameCalculator) { this.gameCalculator = gameCalculator; }