Example #1
0
  /**
   * Returns the map grid squares that are within radius of location
   *
   * @param location The location that serves as the center of the area
   * @param radius The radius of the area
   * @return The map grid squares in the area
   */
  public ArrayList<MapGridSquare> getArea(Location location, int radius) {
    ArrayList<MapGridSquare> mapGridSquares = new ArrayList<MapGridSquare>();

    for (int x = location.getX() - radius + 1; x <= location.getX() + radius - 1; x++) {
      if (x < 0 || x > mapSize[0] - 1) {
        continue;
      }

      for (int z = location.getZ() - radius + 1; z <= location.getZ() + radius - 1; z++) {
        if (z < 0 || z > mapSize[1] - 1) {
          continue;
        }

        MapGridSquare mapGridSquare = this.map.get(new Location(x, z));
        if (!(mapGridSquare.isEmpty())) {
          mapGridSquares.add(mapGridSquare);
        }
      }
    }

    return mapGridSquares;
  }
Example #2
0
  /**
   * Fills up all the locations with map grid square instances and makes sure Location knows the
   * dimensions of the map
   *
   * @param rangeX The length of the map in X direction
   * @param rangeZ The length of the map in Z direction
   * @param guiObjectFactory The gui object factory instance
   */
  public void initialize(int rangeX, int rangeZ, GuiObjectFactory guiObjectFactory) {
    mapSize[0] = rangeX;
    mapSize[1] = rangeZ;
    this.guiGameMap = (GuiGameMapObject) guiObjectFactory.create(GameMap.class, false);

    for (int x = 0; x <= rangeX - 1; x++) {
      for (int z = 0; z <= rangeZ - 1; z++) {
        Location location = new Location(x, z);
        map.put(location, new MapGridSquare(location, guiObjectFactory));
      }
    }

    Location.setMapSize(mapSize);
  }