Class DomainPersistency

java.lang.Object
nz.ac.vuw.ecs.swen225.gp6.persistency.DomainPersistency

public final class DomainPersistency extends Object
This utility class is responsible for saving and loading classes in the Domain package.
  • Method Details

    • fallbackMaze

      public static Maze fallbackMaze()
      Create a fallback maze to be used when the level files cannot be read. As this maze is more basic than the default maze, it should only be used as a fallback.
      Returns:
      The fallback maze
    • loadSave

      public static Domain loadSave(int slot) throws org.dom4j.DocumentException
      Load a saved game from a slot. The associated file exists in res/saves/[slot].xml
      Parameters:
      slot - The slot to load from
      Returns:
      The loaded domain
      Throws:
      org.dom4j.DocumentException - If the XML document is malformed
    • delete

      public static boolean delete(int slot) throws IOException
      Delete a saved game from a slot. The associated file in res/saves/[slot].xml is deleted.
      Parameters:
      slot - The slot to delete
      Returns:
      True if the save was deleted, false otherwise
      Throws:
      IOException - If the file could not be deleted
    • getInitial

      public static Domain getInitial()
      Get the initial domain object. It contains all levels found in res/levels.
      Returns:
      The initial domain
    • save

      public static void save(Domain domain, int slot) throws IOException
      Save a domain object to a save slot. The associated file exists in res/saves/[slot].xml
      Parameters:
      domain - The domain to save
      slot - The save slot to save to
      Throws:
      IOException - If the file could not be written