@Override
  public void loadFromSnapshot(Document doc, Element node) {
    NodeList nl = node.getElementsByTagName("player");
    for (int i = 0; i < nl.getLength(); i++) {
      Element playerEl = (Element) nl.item(i);
      Player player = game.getPlayer(Integer.parseInt(playerEl.getAttribute("index")));
      castles.put(player, Integer.parseInt(playerEl.getAttribute("castles")));
    }

    nl = node.getElementsByTagName("castle");
    for (int i = 0; i < nl.getLength(); i++) {
      Element castleEl = (Element) nl.item(i);
      Position pos = XMLUtils.extractPosition(castleEl);
      Location loc = Location.valueOf(castleEl.getAttribute("location"));
      Castle castle = convertCityToCastle(pos, loc, true);
      boolean isNew = XMLUtils.attributeBoolValue(castleEl, "new");
      boolean isCompleted = XMLUtils.attributeBoolValue(castleEl, "completed");
      if (isNew) {
        newCastles.add(castle);
      } else if (isCompleted) {
        emptyCastles.add(castle);
      } else {
        scoreableCastleVicinity.put(castle, castle.getVicinity());
      }
    }
  }
 @Override
 public void loadTileFromSnapshot(Tile tile, Element tileNode) {
   if (tileNode.hasAttribute("bridge")) {
     Location loc = Location.valueOf(tileNode.getAttribute("bridge"));
     tile.placeBridge(loc);
   }
 }
Beispiel #3
0
	@SuppressWarnings("unchecked")
	public List<Meeple> extractTileMeeples(Element tileEl, Game game, Position pos) throws SnapshotCorruptedException {
		NodeList nl = tileEl.getElementsByTagName("meeple");
		List<Meeple> result = Lists.newArrayList();
		for(int i = 0; i < nl.getLength(); i++) {
			Element el = (Element) nl.item(i);
			Location loc = Location.valueOf(el.getAttribute("loc"));
			Class<? extends Meeple> mt = (Class<? extends Meeple>) XmlUtils.classForName(el.getAttribute("type"));
			int playerIndex = Integer.parseInt(el.getAttribute("player"));
			Meeple meeple = game.getPlayer(playerIndex).getUndeployedMeeple(mt);
			meeple.setLocation(loc);
			meeple.setPosition(pos);
			//don't set feature here. Feature must be set after meeple deployment to correct replace ref during merge
			result.add(meeple);
		}
		return result;
	}
 @Override
 public void loadFromSnapshot(Document doc, Element node) {
   NodeList nl = node.getElementsByTagName("tunnel");
   for (int i = 0; i < nl.getLength(); i++) {
     Element el = (Element) nl.item(i);
     Position pos = XmlUtils.extractPosition(el);
     Location loc = Location.valueOf(el.getAttribute("location"));
     Road road = (Road) getBoard().get(pos).getFeature(loc);
     if (!road.isTunnelEnd()) {
       logger.error("Tunnel end does not exist.");
       continue;
     }
     Player player = game.getPlayer(Integer.parseInt(el.getAttribute("player")));
     boolean isB = "yes".equals(el.getAttribute("b"));
     road.setTunnelEnd(getTunnelId(player, isB));
     game.post(new TunnelPiecePlacedEvent(player, pos, loc, isB));
   }
 }