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

Description

Implements game save and load functionality for the Battleship game.

Changes

  • Added GameService with save/load methods using Java serialization
  • Implemented GameState class to store complete game state
  • Added comprehensive test coverage for save/load scenarios
  • Handles file not found, corrupted files, and incompatible formats
  • Preserves all game state including boards, ships, shots, current player, difficulty, and running time

Features

  • Save Game: Serializes complete game state to file
  • Load Game: Restores game state from file with validation
  • Error Handling: Graceful handling of missing/corrupted files
  • State Preservation: All visible and hidden parts remain consistent after loading
  • File Selection: Player can choose file location and name

Acceptance Criteria Verified

If the game is saved and loaded right away, every visible part and all internal values should be identical If a corrupted file is loaded, an error is displayed and the game remains the same If a completed game is saved and later loaded, it stays finished and waits for a new start

Technical Details

  • Uses Java Object Serialization for persistence
  • Validates loaded game state integrity
  • Maintains hidden ship positions after loading
  • Preserves game timing and difficulty settings

Closes #5

Merge request reports

Loading