Skip to content

Chapter 8

What we will do:

  1. implement messages about shot coordinates, results etc. as well as use user choice from settings how hit information should be displayed - hit or miss only or full;
  2. implement autosave and continue last game;
  3. add a launch screen (splash screen) - static screen displayed during application start. From May 2020 this I a required component if you want to submit your app to AppStore;
  4. add localization - show how to add Polish translation for English strings used so far.

Details for each step:

  1. Download source code for this chapter (download source code).
  2. About 1
    This steps needs some changes in EngineGameBattleship. Some of them are in Board.swift file

    and EngineGameBattleship.swift

    but check carefully what has beed changed. Of course some changes are also in GameBattleshipIOS part.

    When implemented, results should be as in this film (download video).

  3. About 2
    Add an outlet for "Continue last game" button (download video).

    We use, as before for saving information about ship sets, game definitions (both in previous tutorial), and settings (just before) a Codable protocol but this time it needs some customization as we want to save data being of enum typy which does not conform Codable protocol. So me must take some actions to fix this.

    Please read about this here:

    Changes are mede (mostly) in:

    • Ship (start analyzing from this as the most embedded and the easiest)
    • Ships - only minor changes and conforms automaticaly when Ship conforms
    • Boards - copy approach from Ship

    Then we need to save also information about whose turn was as last. Because it is a smal amount of data, we will use UserDefaults. For explanation , please refer to:

    More complete tutorial about saving data in games

    Data storing options summary

    Nice introduction to CoreData (you may think of this like an internal, built-in database)

    You may also find useful this:

    If you are interested in secure save data you may read about some concepts here (an outdated text but main concepts remains)

    I made some decision where, in my opinion, is the best place to put the call to game state saving code: look into SceneDelegate.swift and

    We will not use

    It would be good if you will read some material related to iOS lifecycle and make your own choice:

    When all done in this step, results should be as in this film (download video)

  4. About 3
    Watch video and repeat in your project all the steps (download video).

    You may also want to read these materials

  5. About 4
    Watch video and repeat in your project all the steps (download video).