Class MapGenerator

java.lang.Object
com.deco2800.game.areas.MapGenerator.MapGenerator

public class MapGenerator extends Object
MapGenerator builds a procedurally generated map of desired mapWidth, mapHeight, including an island of islandSize width containing a city of citySize square length. Access map through getMap() function.
  • Field Details

    • legalCoordinates

      public ArrayList<int[]> legalCoordinates
      Stores legal coordinates for players to move to.
  • Constructor Details

    • MapGenerator

      public MapGenerator(int mapWidth, int mapHeight, int cityWidth, int cityHeight, int islandSize) throws IllegalArgumentException
      Initiates a new instance of MapGenerator, with a map width, height, citySize and islandSize
      Parameters:
      mapWidth - width of the map being generated in tiles
      mapHeight - height of the map being generated in tiles
      cityWidth - width of city size in tiles
      cityHeight - height of city size in tiles
      islandSize - total length of the island in tiles
      Throws:
      IllegalArgumentException
  • Method Details

    • generateMap

      public void generateMap()
      Adds the ocean and island tiles to the MapGenerator's map
    • setValidCityDimension

      public int setValidCityDimension(int dimension)
      Returns the valid dimensions of the city to fit an aligned wall around the outsides
      Parameters:
      dimension - width or height of the city in tiles
      Returns:
      the minimum closest dimension necessary to fit a wall around the outskirts of the city
    • getMap

      public char[][] getMap()
      Returns a copy of this MapGenerator's map array
      Returns:
      map containing characters denoting island/city/ocean tiles
    • getOutlineMap

      public char[][] getOutlineMap()
      Returns a copy of this MapGenerator's outline map
      Returns:
      map containing all the edges of the island
    • getWidth

      public int getWidth()
      Returns the current map width
      Returns:
      map width
    • getHeight

      public int getHeight()
      Returns the current map height
      Returns:
      map height
    • getIslandSize

      public int getIslandSize()
      Returns the island size associated with the current map
      Returns:
      the island size within the map
    • getIslandEdges

      public Map<String,Coordinate> getIslandEdges()
      Returns a map containing the coordinates of each island edge
      Returns:
      the coordinates of the island edges of the map
    • getOceanChar

      public char getOceanChar()
      Returns the current char representing an ocean tile
      Returns:
      ocean char
    • getIslandChar

      public char getIslandChar()
      Returns the current char representing an island tile
      Returns:
      island char
    • getCityChar

      public char getCityChar()
      Returns the current char representing a city tile
      Returns:
      city char
    • getFlashChar

      public char getFlashChar()
      Returns the current char representing a flashing tile.
      Returns:
      flash char
    • getCityDetails

      public Map<String,Coordinate> getCityDetails()
      Returns details about the city's extremities
      Returns:
      Map holding the vertices and centre of the city
    • getResourcePlacements

      public List<ResourceSpecification> getResourcePlacements()
      Returns the list of resourceSpecification, holding the placements of each placed resource
      Returns:
      list of resourceSpecification
    • writeMap

      public void writeMap(String path)
      Writes the contents of the map to the text file specified
      Parameters:
      path - the path of the text file to be written to
    • writeMap

      public static void writeMap(char[][] map, String path, int mapWidth, int mapHeight)
      Writes the contents of the map to the text file specified
      Parameters:
      map - 2d char array to write
      path - the path of the text file to be written to
    • copyMap

      public static char[][] copyMap(char[][] map, int mapWidth, int mapHeight)
      Copies the 2D map array into a new char[][] array
      Parameters:
      map - the map to be copied
      Returns:
      a new reference to an identical map array of char
    • getIslandExtremities

      public net.dermetfan.utils.Pair<Integer,Integer> getIslandExtremities()
      Finds the y-coordinate of the extremities of the island.
      Returns:
      Pair of extremities.
    • pickTilesToFlood

      public boolean[][] pickTilesToFlood(boolean[][] tiles, int left, int right)
      Randomly selects tiles to be flooded on next flooding event.
      Parameters:
      tiles - A boolean mapping of all tiles in the game.
      left - The furthest left coordinate of the island.
      right - The furthest right coordinate of the island.
      Returns:
      Mapping of all tiles with tiles to be flooded on the next flooding event set to true.
    • updateFlashingTiles

      public void updateFlashingTiles()
      Flashes tiles that are chosen to flood on the next flooding iteration.
    • flashTiles

      public void flashTiles()
      Given a coordinate (x, y), update the internal representation of the map to flood that tile.
    • flood

      public void flood()
      Floods selected tiles
    • disposeFloodedSquares

      public void disposeFloodedSquares()
      Iterates through the game resources and removes entities that have been flooded.
    • createArrayMap

      public void createArrayMap()
      Get array map of city.
    • addGameResource

      public void addGameResource(Coordinate cord, Entity resource)
    • getBottomLeftX

      public int getBottomLeftX()
    • getBottomLeftY

      public int getBottomLeftY()
    • getCityWidth

      public int getCityWidth()
    • getCityHeight

      public int getCityHeight()
    • getLegalCoordinates

      public ArrayList<int[]> getLegalCoordinates()