Class Map

java.lang.Object
org.bitsquad.warzone.map.Map
Direct Known Subclasses:
Adapter

public class Map extends Object
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
    Constructor
    Description
    Map()
    Constructor for Map class
    Map(Map p_original)
    Copy Constructor for Map
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addContinent(int p_continentId, int p_bonusValue)
    Adds a continent to the map
    void
    addContinent(int p_continentId, String p_continentName, int p_bonusValue)
     
    boolean
    addCountry(int p_countryId, int p_continentId)
    Adding a country to the map
    boolean
    addCountry(int p_countryId, String p_countryName, int p_continentId)
    Adds a country to the map
    boolean
    addNeighbor(int p_sourceCountryId, int p_destinationCountryId)
    Adds a neighbor to a country
    void
    editMap(String p_fileName)
    Loads the contents of .map file to edit If file doesn't exist, create a new .map file
    getContinent(int p_continentId)
    Used to get a particular continent by ID
    Getter method for continents
    boolean
    isContinentSubgraph(int p_continentId)
    Checks if a continent is a subgraph
    boolean
    loadMap(String p_fileName)
    Load contents of the .map text file to Map
    boolean
    removeContinent(int p_continentId)
    Removes a continent from the map
    void
    removeCountry(int p_countryId)
    Removes a country from the map
    void
    removeNeighbor(int p_sourceCountryId, int p_destinationCountryId)
    Remove countries from being neighbors
    void
    saveMap(String p_fileName)
    Write the Map data to a .map text file
    boolean
    Checks if the graph is valid or not
    void
    Used to visualise the game map

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Map

      public Map()
      Constructor for Map class
    • Map

      public Map(Map p_original)
      Copy Constructor for Map
  • Method Details

    • getContinents

      public HashMap<Integer,Continent> getContinents()
      Getter method for continents
      Returns:
      d_continents the continents in a map
    • getContinent

      public Continent getContinent(int p_continentId)
      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 - continentId
      p_bonusValue - bonus value of the continent
    • addContinent

      public void addContinent(int p_continentId, String p_continentName, int p_bonusValue)
    • 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 - countryId
      p_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

      public boolean addCountry(int p_countryId, String p_countryName, int p_continentId)
      Adds a country to the map
      Parameters:
      p_countryId - Country ID
      p_countryName - Country Name
      p_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 - sourceCountryId
      p_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 - sourceCountryId
      p_destinationCountryId - destinationCountryId
    • loadMap

      public boolean loadMap(String p_fileName)
      Load contents of the .map text file to Map
      Parameters:
      p_fileName - Map file name
      Returns:
      true if map loaded successfully
    • saveMap

      public void saveMap(String p_fileName) throws Exception
      Write the Map data to a .map text file
      Parameters:
      p_fileName - FileName
      Throws:
      Exception
    • editMap

      public void editMap(String p_fileName)
      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