Class Domain

java.lang.Object
nz.ac.vuw.ecs.swen225.gp6.domain.Domain

public class Domain extends Object
Represents a complete game state, with levels. Each level includes an inventory, maze, level number direction of heros next move, time limit, current time, etc.
  • Constructor Details

    • Domain

      public Domain(List<Level> levels, int currentLvl)
      constructor with a list of levels.
      Parameters:
      levels - - must be in order.
      currentLvl - - the index of the current level starting at 1
      Throws:
      IndexOutOfBoundsException - if currentLvl is < 1 or > levels.size()
      NullPointerException - if levels is null or contains null.
    • Domain

      public Domain(List<Maze> mazes, Inventory inv, int currentLvl)
      constructor with a list of mazes, and an inventory for current level (all other levels get an empty inv). Levels are created internally from mazes in order. Also timelimits default to 120 seconds, and current times to 0 for each level.
      Parameters:
      mazes - - must be in order.
      inv - - inventory for current level
      currentLvl - - the index of the current level starting at 1
  • Method Details

    • getMazes

      public List<Maze> getMazes()
      gets a list of mazes in order of the levels they are in.
      Returns:
      - list of mazes
    • getCurrentMaze

      public Maze getCurrentMaze()
      gets the maze of current level.
      Returns:
      - maze of current level
    • getInv

      public Inventory getInv()
      gets the inventory of the current level.
      Returns:
      - inventory of the current level
    • getCurrentLevelObject

      public Level getCurrentLevelObject()
      returns current level object.
      Returns:
      - current level object
    • getLevelTimeLimits

      public List<Integer> getLevelTimeLimits()
      returns the list of level time limits, where each element corresponds to a level, and the level is restarted if time runs out.
      Returns:
      the list of level time limits (in order)
    • getEventListener

      public List<Runnable> getEventListener(Domain.DomainEvent event)
      gets the list of event listeners for a given event.
      Parameters:
      event - the event to get the listeners for
      Returns:
      the list of listeners for the given event
    • moveUp

      public void moveUp()
      move hero up in next ping, if possible.
    • moveDown

      public void moveDown()
      move hero down in next ping, if possible.
    • moveLeft

      public void moveLeft()
      move hero left in next ping, if possible.
    • moveRight

      public void moveRight()
      move hero right in next ping, if possible.
    • pingDomain

      public void pingDomain()
      pings the game one step, and replaces the current level object with a new level.
    • getLevels

      public List<Level> getLevels()
      gets the list of levels.
      Returns:
      list of levels
    • getCurrentLevel

      public int getCurrentLevel()
      gets the index of current lvl.
      Returns:
      index of current lvl
    • setCurrentLevel

      public void setCurrentLevel(int lvl)
      sets current level to specified level index.
      Parameters:
      lvl - the level index to switch to
      Throws:
      IndexOutOfBoundsException - if lvl is not at least 1 or is bigger than the number of levels
    • getCurrentTimeLimit

      public int getCurrentTimeLimit()
      gets current levels time limit.
      Returns:
      time limit of current level
    • getCurrentTime

      public long getCurrentTime()
      gets the current time of the current level.
      Returns:
      current time
    • setCurrentTime

      public void setCurrentTime(long time)
      sets current time of current level.
      Parameters:
      time - to set the current time to
    • getTreasuresLeft

      public int getTreasuresLeft()
      gets number of treasures left on current level's maze.
      Returns:
      number of treasures left
    • getGameState

      public Domain.GameState getGameState()
      gets state of the game(won, lost, inbetween levels, playing).
      Returns:
      GameState enum
    • setGameState

      public void setGameState(Domain.GameState state)
      sets state of the game(won, lost, inbetween levels, playing).
      Parameters:
      state - enum
    • isLastLevel

      public boolean isLastLevel()
      finds out if it's the last level of the game.
      Returns:
      true if game is on last level, else false
    • heroIsOnInfo

      public boolean heroIsOnInfo()
      find out if the hero is on info tile.
      Returns:
      true if the hero is on the info tile of the level, else false
    • getInfoHint

      public String getInfoHint()
      gets the message stored in the info tile of this level (note every level can have one info tile at max), must ONLY BE CALLED when hero is on tile info.
      Returns:
      the message stored in the info tile of this level
      Throws:
      RuntimeException - if hero is not on the info tile
    • getInventory

      public List<Tile> getInventory()
      gets a list of current items in the inventory.
      Returns:
      list of items in inventory
    • getGameArray

      public Tile[][] getGameArray()
      gets a copy of current level's maze's game array (shallow copy).
      Returns:
      a copy of current level's maze's game array
    • toString

      public String toString()
      a specific toString method that uses the toString methods in maze and inventory as well as displaying the current level.
      Overrides:
      toString in class Object
      Returns:
      string representation of the Maze and Inventory at the moment
    • addEventListener

      public void addEventListener(Domain.DomainEvent event, Runnable toRun)
      add an event listener to the domain.
      Parameters:
      event - the event to listen for
      toRun - the listener to add
      Throws:
      NullPointerException - if the event or listener is null
    • nextLvl

      public boolean nextLvl()
      If there is another level increments the current level and returns true, else return false.
      Returns:
      true if there is another level