forked from EE422C/learn-git
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.java
37 lines (34 loc) · 1.07 KB
/
Main.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
import java.util.Scanner;
public class Main {
private static Engine engine;
public static void main(final String[] args) {
engine = new Engine("X", "O");
final Scanner scanner = new Scanner(System.in);
int player = 0;
int winner = 0;
while (winner == 0) {
System.out.println("Player " + (player + 1) + "'s turn");
System.out.println();
engine.printBoard();
String input = scanner.nextLine();
int[] coordinates = engine.parseInput(input);
while (coordinates == null) {
System.out.println("Wrong input, try again.");
input = scanner.nextLine();
coordinates = engine.parseInput(input);
}
engine.playerTurn(player, coordinates[0], coordinates[1]);
winner = engine.checkWinner();
if (winner > 0) {
engine.printBoard();
System.out.println("Player " + winner + " wins!");
} else if (engine.checkTie()) {
winner = -1;
engine.printBoard();
System.out.println("Game Tied.");
}
player = (player + 1) % 2;
}
scanner.close();
}
}