Package ch.fusun.baron.map

Examples of ch.fusun.baron.map.Tile


    int width = mapService.getWidth();
    int height = mapService.getHeight();
    for (int i = -1; i < 2; i++) {
      for (int j = -1; j < 2; j++) {
        if (i * j == 0) {// Not diagonal, not the center itself
          Tile current = mapService.getTile((tile.getX() + i + width)
              % width, (tile.getY() + j + height) % height);
          if (country.equals(propertyService.getOwnership(current))) {
            return true;
          }
        }
View Full Code Here


    }
    return newLand;
  }

  private Tile getNearestCityLocation(Tile tile, Collection<City> cities) {
    Tile nearestLocation = new Tile(Integer.MAX_VALUE, Integer.MAX_VALUE);
    double nearestDistance = Double.MAX_VALUE;
    for (City city : cities) {
      Tile cityLocation = cityService.getLocation(city);
      if (cityLocation.absoluteDistanceTo(tile) < nearestDistance) {
        nearestDistance = cityLocation.absoluteDistanceTo(tile);
        nearestLocation = cityLocation;
      }
    }
    return nearestLocation;
  }
View Full Code Here

  @Override
  public void execute(Object object) {
    if (object instanceof Unit) {
      Unit unit = (Unit) object;
      Tile location = unitService.getLocation(unit);
      Dynasty dynasty = playerService.getDynasty(userService.getUser());
      int width = mapService.getWidth();
      int height = mapService.getHeight();
      clientService.execute(new MoveUnitCommand(dynasty, unit, new Tile(
          (location.getX() + getHorizontalDiff() + width) % width,
          (location.getY() + getVerticalDiff() + height) % height)));
    }
  }
View Full Code Here

    return null;
  }

  @Override
  public void moveUnit(Unit unit, Tile destination) {
    Tile location = getLocation(unit);
    if (location != null) {
      removeUnit(unit);
      addUnitToLocation(destination, unit);
    }
  }
View Full Code Here

    return false;
  }

  @Override
  public void removeUnit(Unit unit) {
    Tile location = getLocation(unit);
    Collection<Unit> units = getUnits(location);
    units.remove(unit);
    updateAllListeners(new RemoveUnitDataUpdate(unit));
  }
View Full Code Here

  public void execute() {
    for (Country country : countryService.getCountries()) {
      Collection<Farm> farms = getFarmsForCountry(country);
      Collection<City> cities = getCitiesForCountry(country);
      for (City city : cities) {
        Tile location = cityService.getLocation(city);
        int food = getNumberOfFarmsNearestTo(location, cities, farms);
        city.setPopulation(Math.min(city.getPopulation(), food));
        if (city.isDead()) {
          cityService.removeCity(city);
        }
View Full Code Here

  private int getNumberOfFarmsNearestTo(Tile location,
      Collection<City> cities, Collection<Farm> farms) {
    int food = 0;
    for (Farm farm : farms) {
      Tile farmLocation = farmService.getLocation(farm);
      double shortestDistance = Double.MAX_VALUE;
      Tile nearestLocation = new Tile(Integer.MAX_VALUE,
          Integer.MAX_VALUE);
      for (City city : cities) {
        Tile cityLocation = cityService.getLocation(city);
        if (farmLocation.absoluteDistanceTo(cityLocation) <= shortestDistance) {
          nearestLocation = cityLocation;
          shortestDistance = farmLocation
              .absoluteDistanceTo(cityLocation);
        }
View Full Code Here

  @Override
  public void initialize() {
    for (Country country : countryService.getCountries()) {
      boolean ok = false;
      do {
        Tile tile = getRandomTile();
        if (crossAroundTileIsFree(tile)) {
          setCrossOwnerShipAroundTile(tile, country);
          ok = true;
        }
      } while (!ok);
View Full Code Here

  private Tile getRandomTile() {
    int width = mapService.getWidth();
    int height = mapService.getHeight();
    int x, y;
    Tile tile;
    do {
      x = (int) (width * Math.random());
      y = (int) (height * Math.random());
      tile = mapService.getTile(x, y);
    } while (propertyService.isOwned(tile));
View Full Code Here

TOP

Related Classes of ch.fusun.baron.map.Tile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.