I'm making this program which is basically a Connect 4 game. As you can see below, I have a set of set circles c0,c1,c2 etc. and a duplicate circle c0d which spawns on every button click and comes down to an available slot. In the "background" I made a 2d matrix, a boolean array, which helps me decide to tell when the game is won (by having a the same color 4 times in the row. Of course, I have 6 other rows with the same function too but they basically do the same.
Circle c0d = new Circle(64, 32, 32);
TranslateTransition translate = new TranslateTransition(
Duration.millis(750), c0d);
translate.setToX(0);
FadeTransition fade = new FadeTransition();
fade.setDuration(Duration.seconds(1));
GridPane.setConstraints(c0d, 0, 0);
GridPane.setHalignment(c0d, HPos.CENTER);
grid.getChildren().add(c0d);
if (c0.getFill() == Color.YELLOW) {
c0.setFill(Color.RED);
c1.setFill(Color.RED);
c2.setFill(Color.RED);
c3.setFill(Color.RED);
c4.setFill(Color.RED);
c5.setFill(Color.RED);
c6.setFill(Color.RED);
c0d.setFill(Color.YELLOW);
switch (x0) {
case 0:
translate.setToY(432);
x0++;
wl[5][0] = true;
break;
case 1:
translate.setToY(360);
x0++;
wl[4][0] = true;
break;
case 2:
translate.setToY(288);
x0++;
wl[3][0] = true;
break;
case 3:
translate.setToY(216);
x0++;
wl[2][0] = true;
break;
case 4:
translate.setToY(144);
x0++;
wl[1][0] = true;
break;
case 5:
translate.setToY(72);
x0++;
wl[0][0] = true;
butt0.setDisable(true);
break;
}
} else {
c0.setFill(Color.YELLOW);
c1.setFill(Color.YELLOW);
c2.setFill(Color.YELLOW);
c3.setFill(Color.YELLOW);
c4.setFill(Color.YELLOW);
c5.setFill(Color.YELLOW);
c6.setFill(Color.YELLOW);
c0d.setFill(Color.RED);
switch (x0) {
case 0:
translate.setToY(432);
x0++;
wl[5][0] = false;
break;
case 1:
translate.setToY(360);
x0++;
wl[4][0] = false;
break;
case 2:
translate.setToY(288);
x0++;
wl[3][0] = false;
break;
case 3:
translate.setToY(216);
x0++;
wl[2][0] = false;
break;
case 4:
translate.setToY(144);
x0++;
wl[1][0] = false;
break;
case 5:
translate.setToY(72);
x0++;
wl[0][0] = false;
butt0.setDisable(true);
break;
}
}
for (i = 5; i <= 0; i--) {
if (wl[i][0] == wl[i - 1][0] == wl[i - 2][0] == wl[i - 3][0]) {
System.out.println("WON");
break;
}
Now as you can see, the last for-loop decides when the game is won by comparing the the positions in a row with each other, if they all are "false" which means RED or true which is YELLOW, WON should be output on the console. It doesn't show for some reason. Am I missing something?