Package nz.ac.vuw.ecs.swen225.gp6.domain
Class Domain
java.lang.Object
nz.ac.vuw.ecs.swen225.gp6.domain.Domain
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumenum for domainEvents that the app will be informed of when triggered.static enumenum to inform us of the current state of the game integrity check uses this frequently to check rules of the game accordingly. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddEventListener(Domain.DomainEvent event, Runnable toRun) add an event listener to the domain.intgets the index of current lvl.returns current level object.gets the maze of current level.longgets the current time of the current level.intgets current levels time limit.gets the list of event listeners for a given event.Tile[][]gets a copy of current level's maze's game array (shallow copy).gets state of the game(won, lost, inbetween levels, playing).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.getInv()gets the inventory of the current level.gets a list of current items in the inventory.gets the list of levels.returns the list of level time limits, where each element corresponds to a level, and the level is restarted if time runs out.getMazes()gets a list of mazes in order of the levels they are in.intgets number of treasures left on current level's maze.booleanfind out if the hero is on info tile.booleanfinds out if it's the last level of the game.voidmoveDown()move hero down in next ping, if possible.voidmoveLeft()move hero left in next ping, if possible.voidmove hero right in next ping, if possible.voidmoveUp()move hero up in next ping, if possible.booleannextLvl()If there is another level increments the current level and returns true, else return false.voidpings the game one step, and replaces the current level object with a new level.voidsetCurrentLevel(int lvl) sets current level to specified level index.voidsetCurrentTime(long time) sets current time of current level.voidsetGameState(Domain.GameState state) sets state of the game(won, lost, inbetween levels, playing).toString()a specific toString method that uses the toString methods in maze and inventory as well as displaying the current level.
-
Constructor Details
-
Domain
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
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 levelcurrentLvl- - the index of the current level starting at 1
-
-
Method Details
-
getMazes
gets a list of mazes in order of the levels they are in.- Returns:
- - list of mazes
-
getCurrentMaze
gets the maze of current level.- Returns:
- - maze of current level
-
getInv
gets the inventory of the current level.- Returns:
- - inventory of the current level
-
getCurrentLevelObject
returns current level object.- Returns:
- - current level object
-
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
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
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
gets state of the game(won, lost, inbetween levels, playing).- Returns:
- GameState enum
-
setGameState
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
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
gets a list of current items in the inventory.- Returns:
- list of items in inventory
-
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
a specific toString method that uses the toString methods in maze and inventory as well as displaying the current level. -
addEventListener
add an event listener to the domain.- Parameters:
event- the event to listen fortoRun- 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
-