Class MapGenerator
java.lang.Object
com.deco2800.game.areas.MapGenerator.MapGenerator
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 Summary
FieldsModifier and TypeFieldDescriptionArrayList<int[]>
Stores legal coordinates for players to move to. -
Constructor Summary
ConstructorsConstructorDescriptionMapGenerator
(int mapWidth, int mapHeight, int cityWidth, int cityHeight, int islandSize) Initiates a new instance of MapGenerator, with a map width, height, citySize and islandSize -
Method Summary
Modifier and TypeMethodDescriptionvoid
addGameResource
(Coordinate cord, Entity resource) static char[][]
copyMap
(char[][] map, int mapWidth, int mapHeight) Copies the 2D map array into a new char[][] arrayvoid
Get array map of city.void
Iterates through the game resources and removes entities that have been flooded.void
Given a coordinate (x, y), update the internal representation of the map to flood that tile.void
flood()
Floods selected tilesvoid
Adds the ocean and island tiles to the MapGenerator's mapint
int
char
Returns the current char representing a city tileReturns details about the city's extremitiesint
int
char
Returns the current char representing a flashing tile.int
Returns the current map heightchar
Returns the current char representing an island tileReturns a map containing the coordinates of each island edgeFinds the y-coordinate of the extremities of the island.int
Returns the island size associated with the current mapArrayList<int[]>
char[][]
getMap()
Returns a copy of this MapGenerator's map arraychar
Returns the current char representing an ocean tilechar[][]
Returns a copy of this MapGenerator's outline mapReturns the list of resourceSpecification, holding the placements of each placed resourceint
getWidth()
Returns the current map widthboolean[][]
pickTilesToFlood
(boolean[][] tiles, int left, int right) Randomly selects tiles to be flooded on next flooding event.int
setValidCityDimension
(int dimension) Returns the valid dimensions of the city to fit an aligned wall around the outsidesvoid
Flashes tiles that are chosen to flood on the next flooding iteration.static void
Writes the contents of the map to the text file specifiedvoid
Writes the contents of the map to the text file specified
-
Field Details
-
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 tilesmapHeight
- height of the map being generated in tilescityWidth
- width of city size in tilescityHeight
- height of city size in tilesislandSize
- 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
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
Returns details about the city's extremities- Returns:
- Map holding the vertices and centre of the city
-
getResourcePlacements
Returns the list of resourceSpecification, holding the placements of each placed resource- Returns:
- list of resourceSpecification
-
writeMap
Writes the contents of the map to the text file specified- Parameters:
path
- the path of the text file to be written to
-
writeMap
Writes the contents of the map to the text file specified- Parameters:
map
- 2d char array to writepath
- 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
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
-
getBottomLeftX
public int getBottomLeftX() -
getBottomLeftY
public int getBottomLeftY() -
getCityWidth
public int getCityWidth() -
getCityHeight
public int getCityHeight() -
getLegalCoordinates
-