diff --git a/src/main/java/org/example/TravelGameController.java b/src/main/java/org/example/TravelGameController.java index 30554c59..5fce38f0 100644 --- a/src/main/java/org/example/TravelGameController.java +++ b/src/main/java/org/example/TravelGameController.java @@ -8,6 +8,7 @@ import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.scene.control.Button; +import javafx.scene.control.DialogPane; import javafx.scene.control.Label; import javafx.scene.control.ListView; import javafx.scene.image.Image; @@ -26,6 +27,7 @@ public class TravelGameController { + @FXML private DialogPane winConLabel; @FXML private ImageView mapView; @FXML private StackPane drawingPane; @FXML private Pane gridLayer; @@ -44,6 +46,7 @@ public class TravelGameController { @FXML private Label currentTurnLabel; @FXML private Label currentLocationLabel; @FXML private Label destinationLabel; + @FXML private Label currentPointLabel; private MapVisualizer visualizer; private JourneyService journeyService; @@ -346,6 +349,7 @@ private void updateHud() { currentCreditsLabel.setText(current.getMoney() != null ? current.getMoney().toPlainString() : "-"); currentTurnLabel.setText(String.valueOf(current.getTurnCount())); + currentPointLabel.setText(String.valueOf(current.getPlayerScore())); currentLocationLabel.setText("[" + clampToGrid(current.getPlayerPosX()) + "," + clampToGrid(current.getPlayerPosY()) + "]"); @@ -483,10 +487,12 @@ private void doMove(Long travelerId, PossibleMoves chosen) { + " kom fram till " + targetName + " (rolled=" + journey.getDistanceMoved() + ")" ); + managed.increaseScore(); } tx.commit(); players.set(currentPlayerIndex, managed); + doesPlayerWin(); if (!wonGame) { currentPlayerIndex = (currentPlayerIndex + 1) % players.size(); @@ -501,6 +507,28 @@ private void doMove(Long travelerId, PossibleMoves chosen) { } } + private void doesPlayerWin() { + for (Traveler player : players) { + if (player.checkScore()) { + wonGame = true; + System.out.println(player.getPlayerName() + " Wins the game. Congratulations"); + winConLabel.setContentText(player.getPlayerName() + " Wins the game. Congratulations"); + } + } + } + + + private List distinctLocationsById(List locations) { + java.util.Map byId = new java.util.LinkedHashMap<>(); + for (Location l : locations) { + if (l != null && l.getId() != null) { + byId.putIfAbsent(l.getId(), l); + } + } + return new java.util.ArrayList<>(byId.values()); + } + + private void highlightSelectedMoveButton(Button selected) { for (var node : movesBox.getChildren()) { if (node instanceof Button b) b.setStyle(""); @@ -539,6 +567,8 @@ private void doContinueJourney(Long travelerId) { ); } else { logList.getItems().add("✅ " + safeName(managed) + " kom fram till " + targetName + "!"); + managed.increaseScore(); + doesPlayerWin(); } tx.commit(); diff --git a/src/main/java/org/example/player.java b/src/main/java/org/example/player.java index e77928e2..75afb6bb 100644 --- a/src/main/java/org/example/player.java +++ b/src/main/java/org/example/player.java @@ -5,24 +5,10 @@ abstract class Player { private int playerScore = 0; int credits = 10000; - //set the player name - public void setPlayerName(String playerName) { - this.playerName = playerName; - } - public String getPlayerName() { return playerName; } - public void setPlayerCredits(int credits) { - if (credits < 0){ - System.out.println("Invalid, credits cannot be under zero!"); - this.credits = 0; - } else { - this.credits = credits; - } - } - public int getCredits() { return credits; } diff --git a/src/main/java/org/example/playerMovement.java b/src/main/java/org/example/playerMovement.java index 83bb825a..b52d3143 100644 --- a/src/main/java/org/example/playerMovement.java +++ b/src/main/java/org/example/playerMovement.java @@ -19,10 +19,6 @@ record destinationPos(int destinationX, int destinationY) {} private destinationPos destination; private int playerTurnCount = 0; - public int getTransDiceCount(){ - return selectedTransportDice; - } - public int getTurns(){ return playerTurnCount; } diff --git a/src/main/resources/travelGame.fxml b/src/main/resources/travelGame.fxml index 4d813da8..80700932 100644 --- a/src/main/resources/travelGame.fxml +++ b/src/main/resources/travelGame.fxml @@ -64,6 +64,8 @@