I'm making a checkers game with buttons. To kill another piece, you have to move your piece diagonally over the other piece, but I'm not sure how to ensure that your piece moved over the other piece.
The idea I have for solving this problem is getting the Row and Column of the second button, which is the button that your piece moves to, then subtracting 1 from each Row and Column, then getting the text from that button to test if it is "black" or "red".
first & second = buttons
System.out.println((GridPane.getColumnIndex(second) + " vs " + (GridPane.getColumnIndex(second) - 1)));
if (GridPane.getColumnIndex(second) > 0) {
System.out.println("checking if a button has been jumped");
GridPane.setRowIndex(second, (GridPane.getRowIndex(second) - 1));
GridPane.setColumnIndex(second, (GridPane.getColumnIndex(second) - 1));
System.out.println("this is a printing of the second button name for location " + (GridPane.getColumnIndex(second)) + " " + (GridPane.getRowIndex(second)) + " " + second.getText());
if (second.getText().contains("black")) {
System.out.println("it's a kill");
}
else {
System.out.println("no kill");
GridPane.setRowIndex(second, (GridPane.getRowIndex(second) + 1));
GridPane.setColumnIndex(second, (GridPane.getColumnIndex(second) + 1));
}
}
I'm able to change the Row and Column to what would match the location of the other piece, but when I get the text from that button(second), it doesn't come back as the name "black" or "red", rather just the name of the blank buttons.
My guess is that GridPane's may not work like this, and I just need to come up with another solution, hopefully I won't have to redo my whole code as a 2d array or something.