-
Notifications
You must be signed in to change notification settings - Fork 461
Expand file tree
/
Copy pathChessGame.java
More file actions
49 lines (37 loc) · 1.42 KB
/
ChessGame.java
File metadata and controls
49 lines (37 loc) · 1.42 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package chess;
import chess.piece.Piece;
import java.util.Scanner;
public class ChessGame {
private final Board board = new Board();
private final Scanner scanner = new Scanner(System.in);
public void run() {
Color turn = Color.WHITE;
while (true) {
if (turn.isWhite()) {
System.out.print("WHITE ");
}
if (turn.isBlack()) {
System.out.print("BLACK ");
}
System.out.println("Turn.");
System.out.println("Select Piece Position And Destination Position (ex. A2 A4)");
String moveXY = scanner.nextLine();
String[] split = moveXY.split(" ");
Position start = new Position(Row.change(split[0].charAt(1)), Column.change(split[0].charAt(0)));
Position end = new Position(Row.change(split[1].charAt(1)), Column.change(split[1].charAt(0)));
if (!board.existPieceIn(start)) {
throw new IllegalArgumentException("[ERROR] No Piece");
}
Piece piece = board.getPieceIn(turn, start);
piece.move(end);
if (turn.isWhite()) {
System.out.print("WHITE ");
}
if (turn.isBlack()) {
System.out.print("BLACK ");
}
System.out.printf("%s move: %s to %s%n", piece.name(), start, end);
turn = turn.opposite();
}
}
}