-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.java
43 lines (33 loc) · 892 Bytes
/
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
38
39
40
41
42
43
import chess.ChessGame;
import chess.ChessException;
import java.util.Scanner;
/**
* Main class for chess application
*/
public class Main {
private static void playGameOnCLI() {
ChessGame game = new ChessGame();
Scanner input = new Scanner(System.in);
boolean isRunning = true;
System.out.println("Welcome to chess");
do {
System.out.printf("\n%1$s TURN! \n%2$s%n", game.getTurnColor(), game.printBoard());
System.out.print("Enter Move: ");
String move = input.nextLine();
try {
game.makeMove(move);
if(game.isCheckmate()) {
System.out.printf("\n%s was checkmated!", game.getTurnColor());
isRunning = false;
}
} catch(ChessException e) {
System.err.println(e.getMessage());
}
} while(isRunning);
game.exportGame("testGame");
input.close();
}
public static void main(String[] args) {
playGameOnCLI();
}
}