-
Notifications
You must be signed in to change notification settings - Fork 514
Expand file tree
/
Copy pathPlayer.java
More file actions
33 lines (20 loc) · 720 Bytes
/
Copy pathPlayer.java
File metadata and controls
33 lines (20 loc) · 720 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package practice.snakes.and.ladders;
import lombok.AllArgsConstructor;
import lombok.Data;
@Data
@AllArgsConstructor
public class Player {
String name;
int position;
public boolean moveToPosition(Board board, int diceRoll) {
int newPosition = position + diceRoll;
if (newPosition > Board.BOARD_SIZE) return false;
Cell newCell = board.getCells().get(newPosition);
while (newCell.getSnake() != null || newCell.getLadder() != null) {
newPosition = newCell.getSnake() != null ? newCell.getSnake().newPositionAfterSnakeBite(): newCell.getLadder().newPositionAfterLadderJump();
newCell = board.getCells().get(newPosition);
}
this.position = newPosition;
return true;
}
}