Package nz.ac.vuw.ecs.swen225.gp6.domain
Class Maze
java.lang.Object
nz.ac.vuw.ecs.swen225.gp6.domain.Maze
A class that holds a 2d array of tiles representing the maze in the game.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidhelper class that throws an exception if the location is out of bounds or null.get all the tiles that satisfy the given predicate.Tile[][]gets a copy of tile array.getTileAt(int x, int y) gets the tile at the given x and y co ordinates in the array if location is out of bounds return null typed tile.gets the tile at the given location in the array.intgetTileCount(TileType type) finds the number tiles with this tile type on this maze.getTileLoc(Tile t) finds location of a given tile (exactly the same object).getTileThat(Predicate<Tile> p) gets the first tile that satisfies the given predicate.intheight()get height of tile array.voidpings all tiles in the maze.voidset tile at a given location.voidplace a new tile object of desired tile type at a given location on maze.toString()toString method which creates the board with each tile's given symbol.intwidth()get width of tile array.
-
Constructor Details
-
Maze
Constructs a new 2d array of tiles based on a given 2d tile array.- Parameters:
tileArray- a 2d array of type Tile
-
-
Method Details
-
height
public int height()get height of tile array.- Returns:
- height of maze
-
width
public int width()get width of tile array.- Returns:
- width of maze
-
toString
toString method which creates the board with each tile's given symbol. -
getTileArrayCopy
gets a copy of tile array.
IMPORTANT NOTE: some custom added tiles may not be in the preset tiles and unless the game is running and persistency has to load the tiles onto the game(as java class files to custom.tiles), they won't be able to be instantiated by makeTileFromSymbol and an exception will be thrown.
- Returns:
- a copy of tile array (DEEP CLONE)
- Throws:
RuntimeException- if any tile cannot be instantiated
-
getTileLoc
finds location of a given tile (exactly the same object).- Parameters:
t- tile object to find- Returns:
- loc of tile object if found, else null
- Throws:
NullPointerException- if tile t is null
-
getTileCount
finds the number tiles with this tile type on this maze.- Parameters:
type- to count- Returns:
- number of tiles with give type
-
getTileAt
gets the tile at the given x and y co ordinates in the array if location is out of bounds return null typed tile.- Parameters:
x- x coordy- y coord- Returns:
- the tile at the coords or the Null typed tile if its out of bounds.
- Throws:
IndexOutOfBoundsException- if loc out of maze
-
getTileAt
gets the tile at the given location in the array.- Parameters:
l- location of tile- Returns:
- the tile at the location or the Null typed tile if its out of bounds.
- Throws:
NullPointerException- if loc or tile is nullIndexOutOfBoundsException- if loc out of maze
-
getTileThat
gets the first tile that satisfies the given predicate.- Parameters:
p- predicate- Returns:
- first tile that satisfies the predicate, or Null typed tile if none exist
-
getAllTilesThat
get all the tiles that satisfy the given predicate.- Parameters:
p- predicate- Returns:
- list of all tiles that satisfy the predicate, otherwise an empty list
-
pingMaze
pings all tiles in the maze.- Parameters:
d- - domain where the ping is taking place in (this is since the ping may affect inventory, level index, etc)- Throws:
NullPointerException- if Domain is null
-
setTileAt
place a new tile object of desired tile type at a given location on maze.- Parameters:
loc- - location of tiletype- enum for the tile type to place- Throws:
NullPointerException- if loc is nullIndexOutOfBoundsException- if loc out of maze
-
setTileAt
set tile at a given location.- Parameters:
loc- - location of tiletile- new tile to replace old tile- Throws:
NullPointerException- if loc or tile is nullIndexOutOfBoundsException- if loc out of maze
-
checkLocationIntegrity
helper class that throws an exception if the location is out of bounds or null.- Parameters:
loc- - location to check- Throws:
NullPointerException- if loc is null;IndexOutOfBoundsException- if loc is not in the bounds of the maze;
-