Skip to content

[US-05] Saving and restoring the game

Ivan Esau requested to merge feature/issue-5-us-05-saving-and-restoring-the into master

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

Criterion 1: "If the game is saved and loaded right away, every visible part and all internal values should be identical"

  • Verified by: testSaveAndLoadGameState_AllValuesIdentical() and testCompleteSaveLoadWorkflow_AllValuesIdentical()

Criterion 2: "If a corrupted file is loaded, an error is displayed and the game remains the same"

  • Verified by: testLoadGame_CorruptedFile_ThrowsException(), testLoadGame_WrongFormatFile_ThrowsException(), and testCorruptedFile_ErrorReported_GameUnchanged()

Criterion 3: "If a completed game is saved and later loaded, it stays finished and waits for a new start"

  • Verified by: testSaveAndLoadCompletedGame_StaysFinished() and testCompletedGame_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

Merge request reports

Loading