-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.java
56 lines (42 loc) · 1.53 KB
/
Program.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
package application;
import java.util.InputMismatchException;
import java.util.Scanner;
import chess.ChessException;
import chess.ChessMatch;
import chess.ChessPiece;
import chess.ChessPosition;
/**
* Program
*/
public class Program {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
ChessMatch chessMatch = new ChessMatch();
while (true) {
try {
UI.clearScreen();
UI.printBoard(chessMatch.getPieces());
System.out.println();
System.out.print("Source: ");
ChessPosition source = UI.readChessPosition(sc);
boolean[][] possibleMoves = chessMatch.possibleMoves(source);
UI.clearScreen();
UI.printBoard(chessMatch.getPieces(),possibleMoves);
System.out.println();
System.out.print("Target: ");
ChessPosition target = UI.readChessPosition(sc);
ChessPiece capturedPiece = chessMatch.performChessMove(source, target);
} catch (ChessException e) {
System.out.println();
System.out.println(e.getMessage());
sc.nextLine();// waiting for the Enter
UI.clearScreen();
} catch (InputMismatchException e) {
System.out.println();
System.out.print(e.getMessage());
sc.nextLine();// waiting for the Enter
UI.clearScreen();
}
}
}
}