hanze/game-client

TicTacToe working again (ea5f2dee6a5fe278a529489fd9dd6f166524b53b)
Repositories

commit ea5f2dee6a5fe278a529489fd9dd6f166524b53b
parent ea1b80add41dc610634b3d700ea1afec56b44f08
Author: A Koens <[email protected]>
Date:   Tue,  7 Feb 2023 11:22:45 +0100

TicTacToe working again

Diffstat:
Msrc/main/java/nl/isygameclient/controllers/games/tictactoe/TicTacToeSinglePlayerController.java7++-----
Msrc/main/java/nl/isygameclient/models/games/TicTacToe.java20++++++++++++--------
Msrc/main/resources/nl/isygameclient/css/style.css11+++++++++++
3 files changed, 25 insertions(+), 13 deletions(-)

diff --git a/src/main/java/nl/isygameclient/controllers/games/tictactoe/TicTacToeSinglePlayerController.java b/src/main/java/nl/isygameclient/controllers/games/tictactoe/TicTacToeSinglePlayerController.java @@ -92,7 +92,6 @@ public class TicTacToeSinglePlayerController implements GameController { game.move(currentPlayer, new Vector2D<>(index[0], index[1])); button.setText(currentPlayer.getPlayingAs()); updateCurrentPlayerLabel(); - manager.nextPlayer(); } // Game Over @@ -103,14 +102,12 @@ public class TicTacToeSinglePlayerController implements GameController { private void onGameOver() { disableBoardButtons(); - System.out.println("Game Over"); if (game.isDraw()) { - System.out.println("Draw!"); gameOverText.setText("Draw!"); gameOverText.setVisible(true); } else { - System.out.printf("%s, Is the Winner!\n\n", game.getWinners().get(0)); - gameOverText.setText(String.format("%s, is the Winner!\n\n", game.getWinners().get(0))); + var winner = game.getWinners().get(0).getPlayingAs().toUpperCase(); + gameOverText.setText(String.format("%s, is the Winner!\n\n", winner)); gameOverText.setVisible(true); } } diff --git a/src/main/java/nl/isygameclient/models/games/TicTacToe.java b/src/main/java/nl/isygameclient/models/games/TicTacToe.java @@ -26,10 +26,9 @@ public class TicTacToe extends Game { return false; } - var currentPlayer = playerManager.getCurrentPlayer(); Map<Vector2D<Integer, Integer>, Player> changes = new HashMap<>(); - changes.put(pos, currentPlayer); - board.add(currentPlayer, changes); + changes.put(pos, player); + board.add(player, changes); playerManager.nextPlayer(); return true; @@ -44,12 +43,17 @@ public class TicTacToe extends Game { @Override public boolean isDraw() { - return !Objects.equals(board, null); + for (Player player : playerManager.getPlayers()) { + if (getValidMoves(player).size() > 0) { + return false; + } + } + return true; } @Override public boolean isGameOver() { - return getWinners().size() < 1 || isDraw(); + return getWinners().size() > 0 || isDraw(); } @@ -62,9 +66,9 @@ public class TicTacToe extends Game { boolean middleRow = isPlayer(player, new Vector2D<>(1,0)) && isPlayer(player, new Vector2D<>(1,1)) && isPlayer(player, new Vector2D<>(1,2)); boolean bottomRow = isPlayer(player, new Vector2D<>(2,0)) && isPlayer(player, new Vector2D<>(2,1)) && isPlayer(player, new Vector2D<>(2,2)); - boolean leftColumn = isPlayer(player, new Vector2D<>(0,0)) && isPlayer(player, new Vector2D<>(0,1)) && isPlayer(player, new Vector2D<>(0,2)); - boolean midColumn = isPlayer(player, new Vector2D<>(1,0)) && isPlayer(player, new Vector2D<>(1,1)) && isPlayer(player, new Vector2D<>(1,2)); - boolean rightColumn = isPlayer(player, new Vector2D<>(2,0)) && isPlayer(player, new Vector2D<>(2,1)) && isPlayer(player, new Vector2D<>(2,2)); + boolean leftColumn = isPlayer(player, new Vector2D<>(0,0)) && isPlayer(player, new Vector2D<>(1,0)) && isPlayer(player, new Vector2D<>(2,0)); + boolean midColumn = isPlayer(player, new Vector2D<>(0,1)) && isPlayer(player, new Vector2D<>(1,1)) && isPlayer(player, new Vector2D<>(2,1)); + boolean rightColumn = isPlayer(player, new Vector2D<>(0,2)) && isPlayer(player, new Vector2D<>(1,2)) && isPlayer(player, new Vector2D<>(2,2)); boolean lrCross = isPlayer(player, new Vector2D<>(0,0)) && isPlayer(player, new Vector2D<>(1,1)) && isPlayer(player, new Vector2D<>(2,2)); boolean rlCross = isPlayer(player, new Vector2D<>(0,2)) && isPlayer(player, new Vector2D<>(1,1)) && isPlayer(player, new Vector2D<>(2,0)); diff --git a/src/main/resources/nl/isygameclient/css/style.css b/src/main/resources/nl/isygameclient/css/style.css @@ -100,3 +100,14 @@ .othello-button { -fx-background-color: #388E3C; } + +.ttt-grid { + -fx-border-color: -on-surface; + -fx-border-width: 5; + -fx-border-radius: 2; + } + +.ttt-button { + -fx-background-color: -on-surface; + -fx-text-fill: -on-surface-text; +}