예제 #1
0
        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);
            }
        }
예제 #2
0
        private void HandleFullFrame(Guid currentGameId, IGameCalculator gameCalculator, int score)
        {
            if (CurrentFrame.IsFull(_gameRules.NumberOfRolls))
            {
                gameCalculator.CalculateScore(score, _currentFrameCounter, Frames);

                HandleFrameEntity(currentGameId);

                NextPlayerRollEvent();
            }
            else
            {
                RunAdditionalRollEvent();
            }
        }
예제 #3
0
        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;
        }
예제 #4
0
        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;
            }
        }
예제 #5
0
        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");
        }
예제 #6
0
        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);
        }
예제 #7
0
 public BowlingController(IGameCalculator gameCalculator)
 {
     this.gameCalculator = gameCalculator;
 }