hanze/game-client

Temp Tic Tac Toe Chances (f6425cc5d112cbbd4231ad6baa4461a4fda1de0f)
Repositories

commit f6425cc5d112cbbd4231ad6baa4461a4fda1de0f
parent f6d26072156c2dd2710c1ea5b4f5cc75c408dc43
Author: A Koens <[email protected]>
Date:   Sat, 22 Oct 2022 22:22:28 +0200

Temp Tic Tac Toe Chances

Diffstat:
Msrc/main/java/nl/isygameclient/controllers/TicTacToeGameController.java30++++++++++++------------------
Msrc/main/java/nl/isygameclient/models/TicTacToe.java10+++++++++-
Msrc/main/resources/nl/isygameclient/views/TicTacToeGame.fxml2+-
3 files changed, 22 insertions(+), 20 deletions(-)

diff --git a/src/main/java/nl/isygameclient/controllers/TicTacToeGameController.java b/src/main/java/nl/isygameclient/controllers/TicTacToeGameController.java @@ -8,7 +8,7 @@ import nl.isygameclient.models.TicTacToe; import java.util.ArrayList; -public class TicTacToeGameController implements GameController { +public class TicTacToeGameController { private TicTacToe ttt = new TicTacToe(); @@ -36,14 +36,6 @@ public class TicTacToeGameController implements GameController { private void onMoveButtonClick(JFXButton button) { - // Move - int pos = Integer.parseInt(button.getId()); - System.out.println(pos); - if (ttt.isMoveValid(pos)) { - ttt.move(pos); - button.setText(ttt.getCurrentPlayer()); - ttt.nextPlayer(); - } // Game Over if (ttt.isGameOver()) { System.out.println("Game Over"); @@ -53,14 +45,20 @@ public class TicTacToeGameController implements GameController { } else { System.out.printf("%s, Is the Winner!", winner); } + } else { + // Move + int pos = Integer.parseInt(button.getId()); + System.out.println(pos); + if (ttt.isMoveValid(pos)) { + ttt.move(pos); + button.setText(ttt.getCurrentPlayer()); + ttt.nextPlayer(); + } } } - public void start() { - - } - - public void reset() { + @FXML + protected void onNewGameButtonClick(ActionEvent event) { // Make new Game ttt = new TicTacToe(); @@ -69,8 +67,4 @@ public class TicTacToeGameController implements GameController { button.setText(""); } } - - public void stop() { - - } } diff --git a/src/main/java/nl/isygameclient/models/TicTacToe.java b/src/main/java/nl/isygameclient/models/TicTacToe.java @@ -19,9 +19,17 @@ public class TicTacToe extends Game { board[pos] = players[currentPlayerIndex]; } + + private boolean isDraw(){ + for (String position : board) { + if (position == null) return false; + } + return true; + } + // TODO Draw Condition When board is full public boolean isGameOver() { - return getWinner() != null || board.length >= BOARD_SIZE * BOARD_SIZE; + return getWinner() != null || isDraw(); } public String getWinner() { diff --git a/src/main/resources/nl/isygameclient/views/TicTacToeGame.fxml b/src/main/resources/nl/isygameclient/views/TicTacToeGame.fxml @@ -17,7 +17,7 @@ <padding> <Insets topRightBottomLeft="20"/> </padding> - <JFXButton text="new game"> + <JFXButton text="new game" onAction="#onNewGameButtonClick"> <styleClass> <String fx:value="primary-container"/> <String fx:value="inverse-surface-text"/>