Package org.bitsquad.warzone.map
Class ConquestMap
java.lang.Object
org.bitsquad.warzone.map.ConquestMap
The ConquestMap class serves as an adaptee for the Adapter pattern. It adapts the functionality of the Map class
to be compatible with the ConquestMap requirements.
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a ConquestMap object with an empty list of conquest neighbors and an instance of the Map class.ConquestMap
(Map p_map) Copy constructs a ConquestMap object. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addContinent
(int p_continentId, int p_bonusValue) Adds a continent with the specified ID.void
addContinent
(int p_continentId, String p_continentName, int p_bonusValue) Adds a continent with the specified ID, name, and bonus value.boolean
addCountry
(int p_countryId, int p_continentId) Adds a country with the specified ID.boolean
addNeighbor
(int p_sourceTerritoryId, int p_destinationTerritoryId) Adds a neighbor relationship between two territories.void
addTerritory
(int p_territoryId, String p_territoryName, int p_continentId) Adds a territory with the specified ID, name, and continent ID.void
Edits the map by loading it from the specified file name.Gets the continents from the underlying Map instance.boolean
Loads a map from the specified file name, reading continents and territories from the file.boolean
removeContinent
(int p_continentId) Removes the continent with the specified ID.void
removeCountry
(int p_countryId) Removes the country with the specified ID.void
removeNeighbor
(int p_sourceCountryId, int p_destinationCountryId) Removes a neighbor relationship between two territories.void
Saves the map to a file with the specified name.boolean
Validates the current map using the internal Map instance.void
Visualizes the graph representation of the map using the internal Map instance.
-
Constructor Details
-
ConquestMap
public ConquestMap()Constructs a ConquestMap object with an empty list of conquest neighbors and an instance of the Map class. -
ConquestMap
Copy constructs a ConquestMap object.
-
-
Method Details
-
getContinents
Gets the continents from the underlying Map instance.- Returns:
- HashMap containing continent IDs and corresponding Continent objects.
-
addContinent
Adds a continent with the specified ID, name, and bonus value.- Parameters:
p_continentId
- The ID of the continent.p_continentName
- The name of the continent.p_bonusValue
- The bonus value of the continent.
-
addContinent
public void addContinent(int p_continentId, int p_bonusValue) Adds a continent with the specified ID.- Parameters:
p_continentId
- The ID of the continent.p_bonusValue
- The bonus value of the continent.
-
removeContinent
public boolean removeContinent(int p_continentId) Removes the continent with the specified ID.- Parameters:
p_continentId
- The ID of the continent to be removed.- Returns:
- True if the continent is successfully removed, false otherwise.
-
addCountry
public boolean addCountry(int p_countryId, int p_continentId) Adds a country with the specified ID.- Parameters:
p_countryId
- The ID of the country.p_continentId
- The ID of the continent.- Returns:
- True if the country is successfully added, false otherwise.
-
addTerritory
Adds a territory with the specified ID, name, and continent ID.- Parameters:
p_territoryId
- The ID of the territory.p_territoryName
- The name of the territory.p_continentId
- The ID of the continent.
-
removeCountry
public void removeCountry(int p_countryId) Removes the country with the specified ID.- Parameters:
p_countryId
- The ID of the country to be removed.
-
addNeighbor
public boolean addNeighbor(int p_sourceTerritoryId, int p_destinationTerritoryId) Adds a neighbor relationship between two territories.- Parameters:
p_sourceTerritoryId
- The ID of the source territory.p_destinationTerritoryId
- The ID of the destination territory.- Returns:
- True if the neighbor relationship is successfully added, false otherwise.
-
removeNeighbor
public void removeNeighbor(int p_sourceCountryId, int p_destinationCountryId) Removes a neighbor relationship between two territories.- Parameters:
p_sourceCountryId
- The ID of the source territory.p_destinationCountryId
- The ID of the destination territory.
-
loadMap
Loads a map from the specified file name, reading continents and territories from the file.- Parameters:
p_fileName
- The name of the map file to be loaded.- Returns:
- True if the map is successfully loaded and validated, false otherwise.
-
editMap
Edits the map by loading it from the specified file name. If the file exists, it loads the map; otherwise, it creates a new map file.- Parameters:
p_fileName
- The name of the map file to be edited.
-
saveMap
Saves the map to a file with the specified name. The map is saved with continents and territories, including their neighbors.- Parameters:
p_fileName
- The name of the map file (without extension) to be saved.- Throws:
Exception
- If the map is invalid and cannot be saved.
-
validateMap
public boolean validateMap()Validates the current map using the internal Map instance.- Returns:
- True if the map is valid, false otherwise.
-
visualizeGraph
public void visualizeGraph()Visualizes the graph representation of the map using the internal Map instance.
-