Package org.bitsquad.warzone.map
Class Map
java.lang.Object
org.bitsquad.warzone.map.Map
- Direct Known Subclasses:
Adapter
Represents a game map.
This class defines a map with a list of continents and its Directed Graph as well all related functionality.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addContinent
(int p_continentId, int p_bonusValue) Adds a continent to the mapvoid
addContinent
(int p_continentId, String p_continentName, int p_bonusValue) boolean
addCountry
(int p_countryId, int p_continentId) Adding a country to the mapboolean
addCountry
(int p_countryId, String p_countryName, int p_continentId) Adds a country to the mapboolean
addNeighbor
(int p_sourceCountryId, int p_destinationCountryId) Adds a neighbor to a countryvoid
Loads the contents of .map file to edit If file doesn't exist, create a new .map filegetContinent
(int p_continentId) Used to get a particular continent by IDGetter method for continentsboolean
isContinentSubgraph
(int p_continentId) Checks if a continent is a subgraphboolean
Load contents of the .map text file to Mapboolean
removeContinent
(int p_continentId) Removes a continent from the mapvoid
removeCountry
(int p_countryId) Removes a country from the mapvoid
removeNeighbor
(int p_sourceCountryId, int p_destinationCountryId) Remove countries from being neighborsvoid
Write the Map data to a .map text fileboolean
Checks if the graph is valid or notvoid
Used to visualise the game map
-
Constructor Details
-
Map
public Map()Constructor for Map class -
Map
Copy Constructor for Map
-
-
Method Details
-
getContinents
Getter method for continents- Returns:
- d_continents the continents in a map
-
getContinent
Used to get a particular continent by ID- Parameters:
p_continentId
- Continent id- Returns:
- Continent object
-
addContinent
public void addContinent(int p_continentId, int p_bonusValue) Adds a continent to the map- Parameters:
p_continentId
- continentIdp_bonusValue
- bonus value of the continent
-
addContinent
-
removeContinent
public boolean removeContinent(int p_continentId) Removes a continent from the map- Parameters:
p_continentId
- ID of the continent to be removed- Returns:
- boolean true if an existing continent is being removed, else false
-
addCountry
public boolean addCountry(int p_countryId, int p_continentId) Adding a country to the map- Parameters:
p_countryId
- countryIdp_continentId
- ID of the continent to which the country needs to be added to- Returns:
- boolean if adding a country to an existing continent, else false
-
addCountry
Adds a country to the map- Parameters:
p_countryId
- Country IDp_countryName
- Country Namep_continentId
- ContinentID- Returns:
- boolean
-
removeCountry
public void removeCountry(int p_countryId) Removes a country from the map- Parameters:
p_countryId
- Country Id
-
addNeighbor
public boolean addNeighbor(int p_sourceCountryId, int p_destinationCountryId) Adds a neighbor to a country- Parameters:
p_sourceCountryId
- sourceCountryIdp_destinationCountryId
- destinationCountryId- Returns:
- boolean if both such countries exist, then true, else false
-
removeNeighbor
public void removeNeighbor(int p_sourceCountryId, int p_destinationCountryId) Remove countries from being neighbors- Parameters:
p_sourceCountryId
- sourceCountryIdp_destinationCountryId
- destinationCountryId
-
loadMap
Load contents of the .map text file to Map- Parameters:
p_fileName
- Map file name- Returns:
- true if map loaded successfully
-
saveMap
Write the Map data to a .map text file- Parameters:
p_fileName
- FileName- Throws:
Exception
-
editMap
Loads the contents of .map file to edit If file doesn't exist, create a new .map file- Parameters:
p_fileName
- Map file name
-
isContinentSubgraph
public boolean isContinentSubgraph(int p_continentId) Checks if a continent is a subgraph- Parameters:
p_continentId
- ContinentId- Returns:
- boolean true if the continent is a subgraph
-
validateMap
public boolean validateMap()Checks if the graph is valid or not- Returns:
- boolean true if the graph is valid
-
visualizeGraph
public void visualizeGraph()Used to visualise the game map
-