Esempio n. 1
0
 private void scoreCompletedOnTile(Tile tile) {
   for (Feature feature : tile.getFeatures()) {
     if (feature instanceof Completable) {
       scoreCompleted((Completable) feature, true);
     }
   }
 }
  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;
  }
Esempio n. 3
0
 private static TileSymmetry countBaseSymmetry(Tile tile) {
   for (Feature piece : tile.getFeatures()) {
     if (piece instanceof Road || piece instanceof City) {
       Feature opposite = tile.getFeature(piece.getLocation().rev());
       if (opposite == null || !opposite.getClass().equals(piece.getClass())) {
         return TileSymmetry.NONE;
       }
     }
   }
   for (Feature piece : tile.getFeatures()) {
     if (piece instanceof Road || piece instanceof City) {
       Feature opposite = tile.getFeature(piece.getLocation().rotateCW(Rotation.R90));
       if (opposite == null || !opposite.getClass().equals(piece.getClass())) {
         return TileSymmetry.S2;
       }
     }
   }
   return TileSymmetry.S4;
 }
Esempio n. 4
0
 public void tileEvent(TileEvent ev) {
   Tile tile = ev.getTile();
   if (ev.getType() == TileEvent.PLACEMENT) {
     ResourceManager resourceManager = getClient().getResourceManager();
     Set<Location> farmLocations = new HashSet<>();
     for (Feature f : tile.getFeatures()) {
       if (f instanceof Farm) {
         farmLocations.add(f.getLocation());
       }
     }
     if (farmLocations.isEmpty()) return;
     Map<Location, Area> tAreas = resourceManager.getFeatureAreas(tile, FULL_SIZE, farmLocations);
     areas.put(tile, tAreas);
     refreshHints();
   }
   if (ev.getType() == TileEvent.REMOVE) {
     areas.remove(tile);
     refreshHints();
   }
 }