Beispiel #1
0
        public bool RollOneRound(Random rand, Action <string> writeLine)
        {
            var newLocation       = rand.Next(5) + 1;
            var isLuckyRoll       = (newLocation % 2 != 0);
            var isPenalizingRoll  = rand.Next(9) == 7;
            var _messageCollector = new StringBuilder();

            var currentPlayer = _gameEngine.CurrentPlayer();

            new PlayerRollingMessage(newLocation, _gameEngine.GetCurrentPlayerName()).AppendMessageTo(_messageCollector);
            new PenaltyBoxMessage(_gameEngine.IsCurrentPlayerInPenaltyBox(), isLuckyRoll, _gameEngine.GetCurrentPlayerName())
            .AppendMessageTo(_messageCollector);

            var report = _messageCollector.ToString();

            writeLine(report.Remove(report.LastIndexOf(Environment.NewLine)));

            if ((_gameEngine.IsCurrentPlayerInPenaltyBox() && isLuckyRoll) ||
                !_gameEngine.IsCurrentPlayerInPenaltyBox())
            {
                _gameEngine.ChangeCurrentPlayerLocation(newLocation);
                var currentCategory = _questions.GetCategoryBy(_gameEngine.GetCurrentPlayerLocation());
                _gamePrinter.PrintoutCurrentPlayerNewLocationAndQuestion(
                    _gameEngine.GetCurrentPlayerName(),
                    _gameEngine.GetCurrentPlayerLocation(),
                    _questions.GetCategoryNameBy(_gameEngine.GetCurrentPlayerLocation()),
                    _questions.GetNextQuestionBy(currentCategory));
                _questions.RemoveFirstQuestionOf(currentCategory);
            }
            if (isPenalizingRoll)
            {
                _gamePrinter.PrintoutMessageForIncorrectlyAnsweredQuestion(_gameEngine.GetCurrentPlayerName());
                _gameEngine.PenalizeCurrentPlayer();
                _gameEngine.SetNextCurrentPlayer();
                return(true);
            }
            if (_gameEngine.IsCurrentPlayerInPenaltyBox() && isLuckyRoll)
            {
                _gameEngine.GiveCoinToCurrentPlayer();
                _gamePrinter.PrintoutCorrectAnswer(_gameEngine.GetCurrentPlayerName(),
                                                   _gameEngine.CurrentPlayer().Coins());
                _gameEngine.SetNextCurrentPlayer();
                return(currentPlayer.IsNotWinning());
            }
            if (_gameEngine.IsCurrentPlayerInPenaltyBox())
            {
                _gameEngine.SetNextCurrentPlayer();
                return(true);
            }
            _gameEngine.GiveCoinToCurrentPlayer();
            _gamePrinter.PrintoutCorrectAnswer(_gameEngine.GetCurrentPlayerName(), _gameEngine.CurrentPlayer().Coins());
            _gameEngine.SetNextCurrentPlayer();
            return(currentPlayer.IsNotWinning());
        }
Beispiel #2
0
 public void get_category_name_by_location(int location, QuestionCategory category)
 {
     Assert.That(_questions.GetCategoryBy(location), Is.EqualTo(category));
 }