Skip to content
Snippets Groups Projects
Commit 687040aa authored by jan-schw's avatar jan-schw
Browse files

add condition for game over

parent 89420016
No related branches found
No related tags found
2 merge requests!6Add final version of the game to main branch,!5Add basic implementation
......@@ -16,6 +16,8 @@ public class TicTacToeFX extends Application {
private boolean isXTurn = true;
private boolean isGameOver = false;
@Override
public void start(Stage primaryStage) {
......@@ -64,16 +66,18 @@ public class TicTacToeFX extends Application {
}
private void handleButtonClick(Button button) {
if(button.getText().isEmpty()) {
if(button.getText().isEmpty() && !this.isGameOver) {
if (this.isXTurn) {
button.setText("X");
} else {
button.setText("O");
}
if (checkForWin()) {
this.isGameOver = true;
button.fireEvent(new GameEvent(GameEvent.VICTORY_EVENT));
}
else if(checkForDraw()){
this.isGameOver = true;
button.fireEvent(new GameEvent(GameEvent.DRAW_EVENT));
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment