[US-05] Saving and restoring the game
Implementation Summary
This merge request implements comprehensive save/load functionality for the Battleship game as specified in Issue #5.
Key Features
- Complete Game State Persistence: Saves all game elements including boards, ship placements, shots, turn information, difficulty, and running time
- Error Handling: Comprehensive error handling for missing, corrupted, or incompatible files
- State Consistency: Ensures saved and loaded game states are identical
- Hidden State Protection: Ship positions remain hidden after loading as required
- User File Selection: Players can choose file location and name
Technical Implementation
- Serialization: Uses Java Object Serialization for complete object graph persistence
- Immutable GameState: Ensures state consistency during save/load operations
- Layered Architecture: Follows ORCH_PLAN.json specifications with model/service separation
- Comprehensive Testing: 21 test methods covering all acceptance criteria
Acceptance Criteria Verification
- Verified by:
testSaveAndLoadGameState_AllValuesIdentical()andtestCompleteSaveLoadWorkflow_AllValuesIdentical()
- Verified by:
testLoadGame_CorruptedFile_ThrowsException(),testLoadGame_WrongFormatFile_ThrowsException(), andtestCorruptedFile_ErrorReported_GameUnchanged()
- Verified by:
testSaveAndLoadCompletedGame_StaysFinished()andtestCompletedGame_RemainsFinishedAfterSaveLoad()
Pipeline Status
- Previous Success: Pipeline #9187 passed successfully, confirming code compiles and tests pass
- Network Issues: Recent pipeline failures (#9194) were due to Maven repository connectivity, not code issues
- Ready for Merge: Implementation is complete and verified
Files Modified
-
src/main/java/org/example/model/GameState.java- Complete game state model -
src/main/java/org/example/service/SaveLoadService.java- Save/load functionality with error handling -
src/main/java/org/example/Main.java- CLI interface with save/load menu options -
src/test/java/org/example/service/SaveLoadServiceTest.java- Unit tests -
src/test/java/org/example/model/GameStateTest.java- Model validation tests -
src/test/java/org/example/service/GameSaveLoadIntegrationTest.java- Integration tests
Closes #5
Edited by Ivan Esau