Beispiel #1
0
        public void TakeTurn(Board board, Dice dice, Narrator narrator)
        {
            int  roll;
            bool playerGetsAnotherGo;

            do
            {
                // Roll the dice
                roll = dice.Roll();
                narrator.SayRoll(this, roll);

                // Move the player that many spaces forward on the board
                // Take into account bounce-back
                position += roll;

                // If player over-shoots the final square, they bounce backwards
                if (position > board.Size)
                {
                    int bounce = position - board.Size;
                    position = board.Size - bounce;
                    narrator.SayBounce(this);
                }

                narrator.SaySquareLandedOn(this);

                // Landed on ladder?
                if (board.PlayerIsOnLadder(this, out Ladder ladder))
                {
                    narrator.SayLandedOnLadder(this);
                    position = ladder.To;
                    narrator.SaySquareLandedOn(this);
                }

                // Landed on snake?
                if (board.PlayerIsOnSnake(this, out Snake snake))
                {
                    narrator.SayLandedOnSnake(this);
                    position = snake.To;
                    narrator.SaySquareLandedOn(this);
                }

                // Player ends if they have landed on the final square of the board
                if (board.PlayerIsOnFinalSquare(this))
                {
                    break;
                }

                // Player will get another go if they rolled a six
                playerGetsAnotherGo = false;
                if (roll == 6)
                {
                    narrator.SayAnotherGo(this);
                    playerGetsAnotherGo = true;
                }
            }while (playerGetsAnotherGo);
        }