Skip to content

Feature/player class to db#33

Merged
MartinStenhagen merged 2 commits into
mainfrom
feature/playerClassToDb
Jan 15, 2026
Merged

Feature/player class to db#33
MartinStenhagen merged 2 commits into
mainfrom
feature/playerClassToDb

Conversation

@MartinStenhagen

@MartinStenhagen MartinStenhagen commented Jan 15, 2026

Copy link
Copy Markdown

Summary by CodeRabbit

  • Refactor
    • Refactored core game architecture including player state management, movement systems, and journey mechanics for improved maintainability.
    • Consolidated position tracking and travel advancement logic.
    • Enhanced error handling and exception management throughout game controller with improved state recovery.

✏️ Tip: You can customize this high-level summary in your review settings.

… JourneyService samt anpassningar i TravelGameController. App.javas mainmetod är rensad på gammal kod från tidigare versioner
@coderabbitai

coderabbitai Bot commented Jan 15, 2026

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

This pull request performs a major architectural refactoring: removing the legacy player hierarchy (player.java, playerMovement.java) and procedural game initialization loop from App.java, then restructuring Traveler as a standalone JPA entity with a new public API. TravelGameController is updated to work with the refactored Traveler while enhancing win logic and HUD rendering. JourneyService is adapted to handle advance() returning a boolean.

Changes

Cohort / File(s) Summary
Legacy Player Hierarchy Removal
src/main/java/org/example/player.java, src/main/java/org/example/playerMovement.java
Entire classes removed. Eliminates abstract Player (144 lines with score, credits, penalty/bonus logic) and playerMovement (276 lines with position tracking, movement primitives, transportation selection, dice rolling, and turn handling).
Game Initialization Refactoring
src/main/java/org/example/App.java
Main method body emptied (−235 lines). Removes EntityManager/JPA setup, user input handling, multiplayer branching (cases 2, 3, 4), Traveler persistence, game loop control, and helper methods. Only structural closings remain.
Traveler Entity Modernization
src/main/java/org/example/Traveler.java
Inheritance removed (no longer extends playerMovement); @Table annotation with score index added. New fields posX/posY introduced; money default set to 10000. API expanded with accessor methods (getId, getCurrentLocation, getTargetLocation, getRemainingDistance, getTurnCount, getMoney, getScore, getPosX, getPosY). Method signature changed: advance() now returns boolean. New mutators added: addScore, pay, addMoney, deductMoney, isTravelling, syncPositionFromCurrentLocation.
Game Controller Enhancement
src/main/java/org/example/TravelGameController.java
Added WIN_SCORE constant. Updated HUD rendering to use current.getScore() and current.getCurrentLocation() with null handling. Replaced getPlayerPosX/getPlayerPosY with getPosX/getPosY. Removed startMockJourney. Enhanced doesPlayerWin to fetch fresh Traveler from DB and use numeric WIN_SCORE threshold. DoContinueJourney expanded with null-checks and enhanced exception handling (IllegalStateException "cannot afford" removes player; other exceptions log and refresh UI).
Service Layer Update
src/main/java/org/example/service/JourneyService.java
Updated to capture advance() return value as boolean; invokes traveler.addScore(1) conditionally on arrival.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • Feature/db entity #7: Modifies same core classes (App.java, Traveler.java, JourneyService) with overlapping JPA and lifecycle behavior changes.
  • Feature/player movement #6: Directly removes the Player and playerMovement classes plus App startup logic that this PR added/modified (inverse relationship across same files).
  • Feature/add wincon gui #24: Both PRs modify TravelGameController to add/alter score-based win logic and HUD score display fields.

Poem

🐰 Old hierarchies crumble, player and movement fade,
Traveler stands alone now, a JPA crusade made.
Boolean advances return truth, scores climb ever higher,
App's loop sleeps silent—controller's the fire! 🔥

✨ Finishing touches
  • 📝 Generate docstrings


📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f755ac3 and acfae84.

📒 Files selected for processing (6)
  • src/main/java/org/example/App.java
  • src/main/java/org/example/TravelGameController.java
  • src/main/java/org/example/Traveler.java
  • src/main/java/org/example/player.java
  • src/main/java/org/example/playerMovement.java
  • src/main/java/org/example/service/JourneyService.java

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@MartinStenhagen
MartinStenhagen merged commit 8a81f76 into main Jan 15, 2026
0 of 2 checks passed
@MartinStenhagen
MartinStenhagen deleted the feature/playerClassToDb branch January 15, 2026 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant