player info weer teruggestopt

This commit is contained in:
michiel301b
2025-12-11 10:23:27 +01:00
parent 1ae79daef0
commit 550ee5874b
2 changed files with 15 additions and 4 deletions

View File

@@ -27,6 +27,9 @@ public class GenericGameController<T extends TurnBasedGame<T>> implements GameCo
// Reference to gameView view // Reference to gameView view
protected final GameView gameView; protected final GameView gameView;
// Reference to String gametype
protected final String gameType;
// Reference to game canvas // Reference to game canvas
protected final GameCanvas<T> canvas; protected final GameCanvas<T> canvas;
@@ -39,6 +42,7 @@ public class GenericGameController<T extends TurnBasedGame<T>> implements GameCo
this.canvas = canvas; this.canvas = canvas;
this.game = game; this.game = game;
this.gameType = gameType;
this.gameThreadBehaviour = gameThreadBehaviour; this.gameThreadBehaviour = gameThreadBehaviour;
// Tell thread how to send moves // Tell thread how to send moves
@@ -136,5 +140,12 @@ public class GenericGameController<T extends TurnBasedGame<T>> implements GameCo
@Override @Override
public void updateUI() { public void updateUI() {
canvas.redraw(game.deepCopy()); canvas.redraw(game.deepCopy());
gameView.updatePlayerInfo(
true,
getCurrentPlayer().getName(),
game.getCurrentTurn() == 0 ? "X" : "O",
getPlayer((game.getCurrentTurn() + 1 ) % 2).getName(),
this.gameType
);
} }
} }

View File

@@ -94,7 +94,7 @@ public final class GameView extends ViewWidget {
} }
} }
public void nextPlayer(boolean isMe, String currentPlayer, String currentMove, String nextPlayer, char GameType) { public void updatePlayerInfo(boolean isMe, String currentPlayer, String currentMove, String nextPlayer, String GameType) {
Platform.runLater(() -> { Platform.runLater(() -> {
if (!(hasSet)) { if (!(hasSet)) {
playerHeader.setText(currentPlayer + " vs. " + nextPlayer); playerHeader.setText(currentPlayer + " vs. " + nextPlayer);
@@ -112,8 +112,8 @@ public final class GameView extends ViewWidget {
new GameOverPopup(iWon, winner).show(Pos.CENTER); new GameOverPopup(iWon, winner).show(Pos.CENTER);
} }
private void setPlayerHeaders(boolean isMe, String currentPlayer, String nextPlayer, char GameType) { private void setPlayerHeaders(boolean isMe, String currentPlayer, String nextPlayer, String GameType) {
if (GameType == 'T') { if (GameType.equals("TicTacToe")) {
if (isMe) { if (isMe) {
player1Header.setText("X: " + currentPlayer); player1Header.setText("X: " + currentPlayer);
player2Header.setText("O: " + nextPlayer); player2Header.setText("O: " + nextPlayer);
@@ -124,7 +124,7 @@ public final class GameView extends ViewWidget {
} }
setPlayerInfoTTT(); setPlayerInfoTTT();
} }
else if (GameType == 'R') { else if (GameType.equals("Reversi")) {
if (isMe) { if (isMe) {
player1Header.setText(currentPlayer); player1Header.setText(currentPlayer);
player2Header.setText(nextPlayer); player2Header.setText(nextPlayer);