-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/add wincon gui #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
012a8b5
d0f0838
731b249
e60944f
8457a5f
f4e0f69
7865809
720066b
54a0ac1
a8c5d4b
62a3968
9fbc151
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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<Location> distinctLocationsById(List<Location> locations) { | ||||||||||||||||||||||||||||||||||||||
| java.util.Map<Long, Location> 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()); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+521
to
+529
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # Search for all usages of distinctLocationsById in Java files
rg -n "distinctLocationsById" --type=javaRepository: ithsjava25/project-jpa-grupp-4-g Length of output: 208 🏁 Script executed: # Check the actual file content around lines 521-529 to verify the method definition
sed -n '515,535p' src/main/java/org/example/TravelGameController.java | cat -nRepository: ithsjava25/project-jpa-grupp-4-g Length of output: 921 🏁 Script executed: # Check updateGraphicsWithMoves method around line 434 to see if it uses .distinct()
sed -n '430,445p' src/main/java/org/example/TravelGameController.java | cat -nRepository: ithsjava25/project-jpa-grupp-4-g Length of output: 621 Remove unused method This method is defined at lines 521-529 but is never called anywhere in the codebase. The similar deduplication logic in 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| 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(); | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+570
to
574
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inconsistent placement of In
Proposed fix: Move win check after commit for consistency } else {
logList.getItems().add("✅ " + safeName(managed) + " kom fram till " + targetName + "!");
managed.increaseScore();
- doesPlayerWin();
}
tx.commit();
players.set(currentPlayerIndex, managed);
+
+ if (!managed.isTravelling()) {
+ doesPlayerWin();
+ }
if (!managed.isTravelling() && !wonGame) {📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Loop continues after finding a winner; includes debug statement.
Two issues:
returnorbreakafter settingwonGame = true. If multiple players meet the win condition simultaneously,winConLabelwill be overwritten multiple times.System.out.printlnshould be removed or replaced with proper logging for production code.Proposed fix
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"); + return; } } }📝 Committable suggestion
🤖 Prompt for AI Agents