Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

📚 The CoCalc Library - books, templates and other resources

132938 views
License: OTHER
1
public class ConnectFourGame implements Cloneable {
2
public static final int BOARD_HEIGHT = 6;
3
public static final int BOARD_WIDTH = 7;
4
public static final int WINNING_NR = 4;
5
6
private Color[][] board = new Color[BOARD_WIDTH][BOARD_HEIGHT];
7
private Color lastMove;
8
private Color winner;
9
private boolean isFinished = false;
10
11
//[...]
12
13
public void printBoard() {
14
for (byte y = BOARD_HEIGHT - 1; y >= 0; y--) {
15
System.out.print(y + " ");
16
for (byte x = 0; x < BOARD_WIDTH; x++) {
17
if (board[x][y] == null) {
18
System.out.print(" ");
19
} else if (board[x][y] == Color.RED) {
20
System.out.print("r");
21
} else {
22
System.out.print("w");
23
}
24
}
25
System.out.println("");
26
}
27
System.out.print(" ");
28
for (byte x = 0; x < BOARD_WIDTH; x++) {
29
System.out.print(x);
30
}
31
}
32
}
33
34