-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlay.java
77 lines (66 loc) · 2.68 KB
/
Play.java
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import java.util.*;
class Play {
public static int dieSize;
private static Random random;
public static String whoWins(Board board) {
for (int i = 0; i<board.players.length; i++) {
if(board.players[i].position == board.goalPos)
return board.players[i].name;
}
return null;
}
public static void buildDice() {
System.out.print("Please select the size of the dice you want: ");
int size;
while (true) {
size = IOUtil.readInt();
if (size >0) {
break;
}
System.out.println("Please enter a die size greater than 0.");
}
dieSize = size;
random = new Random();
}
public static int rollDice(Player player) {
System.out.println(player.name + ", it is your turn. Initiate the dice roll");
System.out.println(" by selecting a number between 1 and " + dieSize + ".");
int first;
while (true) {
first = IOUtil.readInt();
if (0 < first && first <= dieSize) {
break;
}
System.out.println("Number between 1 and " + dieSize + " you fool.");
}
return ((first + random.nextInt(dieSize))%dieSize)+1;
}
public static void doTurn(Board board, Player player, int numSteps) {
board.printBoard();
System.out.println("Congratulations, you have rolled a " + numSteps + ".");
System.out.print("Press Enter key to continue ...");
IOUtil.readLine();
for (int i=1; i<=numSteps; i++) {
player.move(board, i==1);
board.printBoard();
System.out.println("You have moved " + i + " of " + numSteps + " steps.");
System.out.print("Press Enter key to continue ...");
IOUtil.readLine();
}
int prevPos = player.position;
if (player.teleport(board)) {
board.printBoard();
System.out.println("Guess what?! You have just been teleported successfully.");
if (player.position > prevPos) {
System.out.println("Congratulations you have advanced " + (player.position -prevPos) + " steps.");
} else {
System.out.println("Oh bugger, you have fallen back " + (prevPos - player.position) + " steps.");
}
}
}
public static void gameOver(Board board) {
System.out.println("LEGENDARY. " + whoWins(board) + " has won GBX's first game.");
System.out.println("SnakeTeleport was extensively developed at Imperial College London.");
System.out.println("This makes you, the WINNER, a LEGENDARY PERSON. Oh baby!");
}
}