Exemplo n.º 1
0
 /** @return : a new Map object exactly the same as this one */
 public GameMap getMapCopy() {
   GameMap newMap = new GameMap();
   for (ContinentData sr : continents) // copy continents
   {
     ContinentData newContinent =
         new ContinentData(Continent.forId(sr.getId()), sr.getId(), sr.getArmiesReward());
     newMap.add(newContinent);
   }
   for (RegionData r : regions) // copy regions
   {
     RegionData newRegion =
         new RegionData(
             Region.forId(r.getId()),
             r.getId(),
             newMap.getContinent(r.getContinentData().getId()),
             r.getPlayerName(),
             r.getArmies());
     newMap.add(newRegion);
   }
   for (RegionData r : regions) // add neighbors to copied regions
   {
     RegionData newRegion = newMap.getRegion(r.getId());
     for (RegionData neighbor : r.getNeighbors())
       newRegion.addNeighbor(newMap.getRegion(neighbor.getId()));
   }
   return newMap;
 }
Exemplo n.º 2
0
 /**
  * add a Continent to the map
  *
  * @param continent : Continent to be added
  */
 public void add(ContinentData continent) {
   for (ContinentData s : continents)
     if (s.getId() == continent.getId()) {
       System.err.println("Continent cannot be added: id already exists.");
       return;
     }
   continents.add(continent);
 }
Exemplo n.º 3
0
 /**
  * @param id : a Continent id number
  * @return : the matching Continent object
  */
 public ContinentData getContinent(int id) {
   for (ContinentData continent : continents) if (continent.getId() == id) return continent;
   System.err.println("Could not find continent with id " + id);
   return null;
 }