コード例 #1
0
 @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));
   }
 }
コード例 #2
0
 public void placeTunnelPiece(Position p, Location loc, boolean isB) {
   Road road = (Road) getBoard().get(p).getFeature(loc);
   if (!road.isTunnelOpen()) {
     throw new IllegalStateException("No open tunnel here.");
   }
   Player player = game.getActivePlayer();
   int connectionId = getTunnelId(player, isB);
   decreaseTunnelTokens(player, isB);
   for (Road r : tunnels) {
     if (r.getTunnelEnd() == connectionId) {
       r.setTunnelEdge(road);
       road.setTunnelEdge(r);
       break;
     }
   }
   road.setTunnelEnd(connectionId);
   placedTunnelCurrentTurn = road;
   game.post(new TunnelPiecePlacedEvent(player, p, loc, isB));
 }