/** @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; }
/** * 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); }
/** * @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; }