Ejemplo n.º 1
0
  public void tilePlaced(Tile tile, TileLayer tileLayer) {
    Position p = tile.getPosition();

    removeLayer(AbstractTilePlacementLayer.class);
    removeLayer(PlacementHistory.class);

    if (p.x == left) --left;
    if (p.x == right) ++right;
    if (p.y == top) --top;
    if (p.y == bottom) ++bottom;

    tileLayer.tilePlaced(tile);

    if (client.getSettings().isShowHistory()) {
      showRecentHistory();
    }
    boolean initialPlacement =
        client.getActivePlayer() == null; // if active player is null we are placing initial tiles
    if ((!initialPlacement && !client.isClientActive())
        || (initialPlacement && tile.equals(client.getGame().getCurrentTile()))) {
      getAnimationService()
          .registerAnimation(tile.getPosition(), new RecentPlacement(tile.getPosition()));
    }
    repaint();
  }
Ejemplo n.º 2
0
 private BridgeAction prepareTileBridgeAction(Tile tile, BridgeAction action, Location bridgeLoc) {
   if (isBridgePlacementAllowed(tile, tile.getPosition(), bridgeLoc)) {
     if (action == null) action = new BridgeAction();
     action.add(new FeaturePointer(tile.getPosition(), bridgeLoc));
   }
   return action;
 }
Ejemplo n.º 3
0
	private void createTileElements(Game game) {
		tileElemens = new HashMap<Position, Element>();
		Element parent = doc.createElement("tiles");
		if (game.getCurrentTile() != null) {
			parent.setAttribute("next", game.getCurrentTile().getId());
		}
		root.appendChild(parent);
		//for()
		for(String group : game.getTilePack().getGroups()) {
			Element el = doc.createElement("group");
			el.setAttribute("name", group);
			el.setAttribute("active", "" + game.getTilePack().isGroupActive(group));
			parent.appendChild(el);
		}
		for(Tile tile : game.getBoard().getAllTiles()) {
			Element el = doc.createElement("tile");
			el.setAttribute("name", tile.getId());
			el.setAttribute("rotation", tile.getRotation().name());
			XmlUtils.injectPosition(el, tile.getPosition());
			parent.appendChild(el);
			tileElemens.put(tile.getPosition(), el);
		}
		for(String tileId : game.getBoard().getDiscardedTiles()) {
			Element el = doc.createElement("discard");
			el.setAttribute("name", tileId);
			parent.appendChild(el);
		}
	}
Ejemplo n.º 4
0
 public void update() {
   history.clear();
   int i = placedTilesView.size();
   int limit = getGame().getAllPlayers().length;
   for (Tile t : placedTilesView) {
     if (i <= limit) {
       history.put(t.getPosition(), "" + i);
     }
     i--;
   }
 }
Ejemplo n.º 5
0
 protected void deploy(Tile tile, Location loc, Feature feature) {
   DeploymentCheckResult check = isDeploymentAllowed(feature);
   if (!check.result) {
     throw new IllegalArgumentException(check.error);
   }
   feature.addMeeple(this);
   setPosition(tile.getPosition());
   setLocation(loc);
   setFeature(feature);
   game.post(new MeepleEvent(MeepleEvent.DEPLOY, this));
 }
Ejemplo n.º 6
0
 private BridgeAction prepareBridgeAction() {
   BridgeAction action = null;
   Tile tile = game.getCurrentTile();
   action = prepareTileBridgeAction(tile, action, Location.NS);
   action = prepareTileBridgeAction(tile, action, Location.WE);
   for (Entry<Location, Tile> entry :
       getBoard().getAdjacentTilesMap(tile.getPosition()).entrySet()) {
     Tile adjacent = entry.getValue();
     Location rel = entry.getKey();
     action = prepareTileBridgeAction(adjacent, action, getBridgeLocationForAdjacent(rel));
   }
   return action;
 }
Ejemplo n.º 7
0
  @Override
  public void paint(Graphics2D g2) {
    // TODO nice shadow
    if (!getClient().getGridPanel().containsDecoration(AbstractTilePlacementLayer.class)) {
      g2.setColor(Color.WHITE);
      int squareSize = getSquareSize(), thickness = squareSize / 11;
      for (Tile tile : placedTiles) {
        Position p = tile.getPosition();
        int x = getOffsetX(p), y = getOffsetY(p);
        g2.fillRect(
            x - thickness, y - thickness, squareSize + 2 * thickness, squareSize + 2 * thickness);
      }
    }

    for (Tile tile : placedTiles) {
      Image img = getClient().getResourceManager().getTileImage(tile);
      g2.drawImage(
          img,
          getAffineTransform(img.getWidth(null), tile.getPosition(), tile.getRotation()),
          null);
    }
  }
Ejemplo n.º 8
0
 @Override
 public boolean visit(Feature feature) {
   cloister = (Cloister) feature;
   Position pos = cloister.getTile().getPosition();
   List<Tile> neigbouringTiles = game.getBoard().getAdjacentAndDiagonalTiles(pos);
   neigbouringTilesCount = neigbouringTiles.size();
   if (lbCap != null) {
     collectLittleBuildings(cloister.getTile().getPosition());
     for (Tile tile : neigbouringTiles) {
       collectLittleBuildings(tile.getPosition());
     }
   }
   return true;
 }
Ejemplo n.º 9
0
  public BridgeAction prepareMandatoryBridgeAction() {
    Tile tile = game.getCurrentTile();
    for (Entry<Location, Tile> entry :
        getBoard().getAdjacentTilesMap(tile.getPosition()).entrySet()) {
      Tile adjacent = entry.getValue();
      Location rel = entry.getKey();

      char adjacentSide = adjacent.getEdge(rel.rev());
      char tileSide = tile.getEdge(rel);
      if (tileSide != adjacentSide) {
        Location bridgeLoc = getBridgeLocationForAdjacent(rel);
        BridgeAction action = prepareTileBridgeAction(tile, null, bridgeLoc);
        if (action != null) return action;
        return prepareTileBridgeAction(adjacent, null, bridgeLoc);
      }
    }
    throw new IllegalStateException();
  }
Ejemplo n.º 10
0
  private Castle replaceCityWithCastle(Tile tile, Location loc) {
    ListIterator<Feature> iter = tile.getFeatures().listIterator();
    City city = null;
    while (iter.hasNext()) {
      Feature feature = iter.next();
      if (feature.getLocation() == loc) {
        city = (City) feature;
        break;
      }
    }
    List<Meeple> meeples =
        new ArrayList<>(city.getMeeples()); // collection copy required!!! undeploy modify it
    for (Meeple m : meeples) {
      m.undeploy();
    }
    Castle castle = new Castle();
    castle.setTile(tile);
    castle.setId(game.idSequnceNextVal());
    castle.setLocation(loc.rotateCCW(tile.getRotation()));
    iter.set(castle);

    for (Feature f : tile.getFeatures()) { // replace also city references
      if (f instanceof Farm) {
        Farm farm = (Farm) f;
        Feature[] adjoining = farm.getAdjoiningCities();
        if (adjoining != null) {
          for (int i = 0; i < adjoining.length; i++) {
            if (adjoining[i] == city) {
              adjoining[i] = castle;
              break;
            }
          }
        }
      }
    }

    FeaturePointer fp = new FeaturePointer(tile.getPosition(), loc);
    for (Meeple m : meeples) {
      if (m.getPlayer() == game.getActivePlayer() && m.isDeploymentAllowed(castle).result) {
        m.deploy(fp);
      }
    }
    return castle;
  }
Ejemplo n.º 11
0
  private boolean isTilePlacementWithOneAdjacentBridgeAllowed(Tile tile, Position p) {
    boolean bridgeUsed = false;
    for (Entry<Location, Tile> e : getBoard().getAdjacentTilesMap(p).entrySet()) {
      Tile adjacent = e.getValue();
      Location rel = e.getKey();

      char tileSide = tile.getEdge(rel);
      char adjacentSide = adjacent.getEdge(rel.rev());

      if (tileSide != adjacentSide) {
        if (bridgeUsed) return false;
        if (tileSide != 'R') return false;

        Location bridgeLoc = getBridgeLocationForAdjacent(rel);
        if (!isBridgePlacementAllowed(adjacent, adjacent.getPosition(), bridgeLoc)) return false;
        bridgeUsed = true;
      }
    }
    return bridgeUsed; // ok if exactly one bridge is used
  }