package smims.networking.model;

public class Turn {
	private final Player player;
	private final IBoard board;
	private final DiceRoller diceRoller;
	private int rolledCount = 0;
	private int mustRollCount = 0;
	private TurnState turnState;
	
	
	public Turn(Player player, IBoard board, DiceRoller diceRoller) {
		this.player = player;
		this.board = board;
		this.diceRoller = diceRoller;
	}
	
	public Player getPlayer() {
		return player;
	}
	
	public void moveCharacter(int characterPos) {
		
	}
	
	public void rollDice() throws MoveNotAllowedException {
		EnsurePlayerCanRollDice();
	}

	private void EnsurePlayerCanRollDice() throws MoveNotAllowedException {
		if(!(turnState == TurnState.ExpectRoll) && rolledCount < mustRollCount) {
			throw new MoveNotAllowedException();
		}
	}

	public boolean isOfPlayer(int playerId) {
		return getPlayer().getPlayerId() == playerId;
	}
	
	boolean isOver() {
		return turnState == TurnState.Finished;
	}
	
	private void doThreeTurns(Player p) throws Exception {
		for (int i = 0; i < 3; i++) {
			diceRoller.rollDice();
			if (gameState.myDice.getResult() == 6) {
				turnWithoutRoll(p);
				break;
			}
		}
	}
}

@@ -187,19 +187,18 @@
 te int m
-ust
+ax
 RollCoun
@@ -193,33 +193,33 @@
  maxRollCount = 
-0
+1
 ;%0A%09private TurnS
@@ -488,18 +488,686 @@
 os) 
-%7B
+throws MoveNotAllowedException %7B%0A%09%09EnsurePlayerCanMoveCharacter();%0A%09%09moveCharacterAtPosition(characterPos);%0A%09%09if (diceRoller.getResult() == 6) %7B%0A%09%09%09transitionToRollingState();%0A%09%09%7D else %7B%0A%09%09%09transitionToFinishedState();%0A%09%09%7D%0A%09%7D%0A%09%0A%09private void moveCharacterAtPosition(int characterPos) %7B%0A%09%09board.moveCharacter(iCharacter, distance);%0A%09%7D%0A%0A%09private void EnsurePlayerCanMoveCharacter() throws MoveNotAllowedException %7B%0A%09%09if (turnState != TurnState.ExpectMove) %7B%0A%09%09%09throw new MoveNotAllowedException();%0A%09%09%7D%0A%09%09%0A%09%7D%0A%0A%09private void transitionToRollingState() %7B%0A%09%09turnState = TurnState.ExpectRoll;%0A%09%09%0A%09%7D%0A%0A%09private void transitionToFinishedState() %7B%0A%09%09turnState = TurnState.Finished;
 %0A%09%09%0A%09%7D%0A
-%09
 %0A
+
 %09pub
@@ -1248,16 +1248,330 @@
 Dice();%0A
+%09%09diceRoller.rollDice();%0A%09%09rolledCount++;%0A%09%09if ((maxRollCount != 1 && diceRoller.getResult() == 6) %7C%7C maxRollCount == 1) %7B%0A%09%09%09transitionToMoveState();%0A%09%09%7D else if (maxRollCount == rolledCount) %7B%0A%09%09%09transitionToFinishedState();%0A%09%09%7D%0A%09%7D%0A%0A%09private void transitionToMoveState() %7B%0A%09%09turnState = TurnState.ExpectMove;%0A%09%09%0A
 %09%7D%0A%0A%09pri
@@ -1703,11 +1703,10 @@
  %3C m
-ust
+ax
 Roll
@@ -1874,24 +1874,24 @@
  isOver() %7B%0A
+
 %09%09return tur
@@ -1927,213 +1927,6 @@
 %0A%09%7D%0A
-%09%0A%09private void doThreeTurns(Player p) throws Exception %7B%0A%09%09for (int i = 0; i %3C 3; i++) %7B%0A%09%09%09diceRoller.rollDice();%0A%09%09%09if (gameState.myDice.getResult() == 6) %7B%0A%09%09%09%09turnWithoutRoll(p);%0A%09%09%09%09break;%0A%09%09%09%7D%0A%09%09%7D%0A%09%7D%0A
 %7D%0A

Implement Turn