Class Maze

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

public class Maze extends Object
A class that holds a 2d array of tiles representing the maze in the game.
  • Constructor Details

    • Maze

      public Maze(Tile[][] tileArray)
      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

      public String toString()
      toString method which creates the board with each tile's given symbol.
      Overrides:
      toString in class Object
      Returns:
      the board in string format
    • getTileArrayCopy

      public Tile[][] 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

      public Loc getTileLoc(Tile t)
      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

      public int getTileCount(TileType type)
      finds the number tiles with this tile type on this maze.
      Parameters:
      type - to count
      Returns:
      number of tiles with give type
    • getTileAt

      public Tile 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.
      Parameters:
      x - x coord
      y - 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

      public Tile getTileAt(Loc l)
      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 null
      IndexOutOfBoundsException - if loc out of maze
    • getTileThat

      public Tile getTileThat(Predicate<Tile> p)
      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

      public List<Tile> getAllTilesThat(Predicate<Tile> p)
      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

      public void pingMaze(Domain d)
      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

      public void setTileAt(Loc loc, TileType type)
      place a new tile object of desired tile type at a given location on maze.
      Parameters:
      loc - - location of tile
      type - enum for the tile type to place
      Throws:
      NullPointerException - if loc is null
      IndexOutOfBoundsException - if loc out of maze
    • setTileAt

      public void setTileAt(Loc loc, Tile tile)
      set tile at a given location.
      Parameters:
      loc - - location of tile
      tile - new tile to replace old tile
      Throws:
      NullPointerException - if loc or tile is null
      IndexOutOfBoundsException - if loc out of maze
    • checkLocationIntegrity

      public void checkLocationIntegrity(Loc loc)
      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;