-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.java
More file actions
33 lines (25 loc) · 1.12 KB
/
main.java
File metadata and controls
33 lines (25 loc) · 1.12 KB
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
public class Main {
public static void main(String[] args) {
System.out.println("Two or three dimensions?");
int dimensionNumber = BoardThreeD.scanner.nextInt();
while (dimensionNumber != 2 && dimensionNumber != 3) {
System.out.println("Please type either 2 or 3.");
dimensionNumber = BoardThreeD.scanner.nextInt();
}
System.out.println("Please enter board width:");
int boardwidth = BoardThreeD.scanner.nextInt();
while (boardwidth < 0) {
System.out.println("Please enter a positive number.");
boardwidth = BoardThreeD.scanner.nextInt();
}
BoardIO playBoard = dimensionNumber == 3 ? new BoardThreeD(boardwidth) : new BoardTwoD(boardwidth);
BoardTwoD.Status winner = playBoard.play();
if (winner == BoardTwoD.Status.X || winner == BoardTwoD.Status.O) {
System.out.println("Player " + BoardThreeD.statusToString(winner) + " won! Congratulations!");
}
else {
System.out.println("It's a draw!");
}
playBoard.printBoard();
}
}