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); }
public void SelectFirstPlayer() { // Each player rolls the dice // Whoever gets highest roll goes first // If two or more players both roll same same highest roll, they roll again // Until just one player got the highest roll narrator.SaySelectingFirstPlayer(); Player[] candidates = players; while (candidates.Length > 1) { int highestRoll = 0; List <Player> highestRollingPlayers = new List <Player>(); foreach (Player player in candidates) { int roll = dice.Roll(); narrator.SayRoll(player, roll); if (roll > highestRoll) { highestRoll = roll; highestRollingPlayers.Clear(); highestRollingPlayers.Add(player); } else if (roll == highestRoll) { highestRollingPlayers.Add(player); } } candidates = highestRollingPlayers.ToArray(); } // We only have one candidate remaining, so they are the single highest rolling player // and will be the player to go first currentPlayer = candidates[0]; narrator.SayFirstPlayer(currentPlayer); }