-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGameControl.java
65 lines (65 loc) · 2.3 KB
/
GameControl.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
57
58
59
60
61
62
63
64
65
import java.io.FileNotFoundException;
import org.code.playground.*;
import org.code.media.*;
public class GameControl {
private static ChessBoard board;
private static String currentTurn;
public static void start () throws FileNotFoundException, PlaygroundException {
currentTurn = "White";
board = new ChessBoard();
}
public static String getTurn() {
return currentTurn;
}
public static void switchTurn() {
currentTurn = (currentTurn.equals("White") ? "Black" : "White");
}
public static void checkForEnd() {
ChessBoard.setPlayerHasMove(false);
try {
for (Piece thisPiece : ChessBoard.getPiecesArray()[currentTurn.equals("White") ? 0 : 1]) {
ChessBoard.getPossibleMoves(thisPiece);
}
if (CheckLogic.inCheck(ChessBoard.getPiecesArray(), currentTurn) && !ChessBoard.getPlayerHasMove()) {
System.out.println("Checkmate! " + (currentTurn == "White" ? "Black" : "White") + " wins!");
ChessBoard.showOverlay(currentTurn == "White" ? "Black" : "White");
ChessBoard.myChessBoard.end("win.wav");
} else if (!ChessBoard.getPlayerHasMove()) {
System.out.println("Stalemate!");
ChessBoard.showOverlay("Draw");
ChessBoard.myChessBoard.end();
}
} catch (Exception e) {
System.out.println("Exception in method checkForEnd() checkmate / stalemate check: " + e);;
}
boolean draw = true;
int bishopCount = 0;
int knightCount = 0;
for (Piece[] x : ChessBoard.getPiecesArray()) {
for (Piece y : x) {
if (y.getType() != null && draw) {
if (y.getType().equals("Queen") || y.getType().equals("Rook") || y.getType().equals("Pawn")) {
draw = false;
} else if (y.getType().equals("Bishop")) {
bishopCount++;
} else if (y.getType().equals("Knight")) {
knightCount++;
}
}
}
if (bishopCount > 1 || (bishopCount == 1 && knightCount >= 1)) {
draw = false;
}
}
if (draw) {
try {
System.out.println("Draw!");
ChessBoard.showOverlay("Draw");
ChessBoard.myChessBoard.playSound("move_sound.wav");
ChessBoard.myChessBoard.end();
} catch (Exception e) {
System.out.println("Exception in method checkForEnd() draw check: " + e);
}
}
}
}