Example #1
0
  // generate the capital by finding the center of the largest landmass.
  // this method can only be called after the AgriculturalUnit's regions have been set.
  private MapPoint calCapitolLocation() {
    if (entities == null) throw new RuntimeException("(!) regions not set!");
    if (entities.isEmpty()) throw new RuntimeException("(!) no regions !");

    int maxArea = 0;
    Area largest = null;

    for (AgriculturalUnit region : entities) {
      Area poly = region.getArea();
      int area = (int) (poly.getBounds().getWidth() * poly.getBounds().getHeight());
      if (area >= maxArea) {
        largest = poly;
        maxArea = area;
      }
    }

    int x = (int) largest.getBounds().getCenterX();
    int y = (int) largest.getBounds().getCenterY();

    return AgriculturalUnit.converter.pointToMapPoint(new Point(x, y));
  }
Example #2
0
 /** @param tile AgriculturalUnit to add to country */
 public void addAgriculturalUnit(AgriculturalUnit tile) {
   entities.add(tile);
   area.add(tile.getArea());
 }