Android Open Source - ZorbsCity Building






From Project

Back to project page ZorbsCity.

License

The source code is released under:

GNU General Public License

If you think the Android project ZorbsCity listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package jonathan.geoffroy.zorbscity.model.cityObjects.buildings;
//  w  ww . j a v a2s  .c om
import jonathan.geoffroy.zorbscity.model.Simulator;
import jonathan.geoffroy.zorbscity.model.cityObjects.resources.Resource;
import jonathan.geoffroy.zorbscity.model.helpers.NeededList;
import jonathan.geoffroy.zorbscity.model.helpers.ResourcesList;

/**
 * A Building is an abstract Structure which needs resources to live/work.
 * A Building can also be destroyed by time, so it have a weakness value: when this weakness value up to WEAKNESS_WHEN_DESTROYED, it is broken.
 * A special Building should be develop to down the weakness value to 0.
 * Note that Building should have at least one access to a Road, and can go anywhere on the city, but only if there is a road from the enterprise to the destination.
 * @author Jonathan GEOFFROY
 * @version 0.1
 */
public abstract class Building extends Construction {
  /**
   * auto-generated serial (using eclipse)
   */
  private static final long serialVersionUID = -1312343388926034677L;

  public final static int WEAKNESS_WHEN_DESTROYED = 100;

  /**
   * List of resources the Enterprise have to create a new resource, or House to upgrade
   */
  protected ResourcesList resources;

  /**
   * List of resources the Enterprise have to create a new resource, or House to upgrade
   */
  protected NeededList needed;

  public Building() {
    super();
    resources = new ResourcesList();
    needed = new NeededList();
  }

  public Building(Building b) {
    super(b);
    resources = new ResourcesList();
    needed = new NeededList();
  }

  /**
   * Find the amount of resources is needed for this Building.
   * Do not check the number of amount the building has, but just the theorical needing.
   * By default, a Building need 1 of this resource if resources.contains(r), 0 otherwise.
   * @param r the resource to check
   * @return the amount of r is needed for this Building.
   */
  public int neededAmount(int resourceType) {
    return needed.amountNeeded(resourceType);
  }

  /**
   * delegate method for resources.enoughResources()
   * @return true if there are at least 1 amount of each Resource in resources list
   */
  public boolean enoughResources() {
    return resources.enoughResources(needed);
  }

  /**
   * delegate method for resources.enoughResources(r)
   * check if this Building have enough resources of r
   * @param r the resource to check
   * @return true if the resource type is not in the needed list, or return amountNeeded(r)
   */
  public boolean enoughResources(int resourceType) {
    return resources.enoughResources(needed, resourceType);
  }

  /**
   * delegate method for resources.add(<r>)
   * @param sim the simulator which add the resource into this building
   * @param r the resource added into this building
   */
  public void addResource(Simulator sim, Resource r) {
    resources.add(r);
  }

  public ResourcesList getResources() {
    return resources;
  }

  public NeededList getNeeded() {
    return needed;
  }



}




Java Source Code List

jonathan.geoffroy.zorbscity.MainActivity.java
jonathan.geoffroy.zorbscity.Main.java
jonathan.geoffroy.zorbscity.ZorbCityGame.java
jonathan.geoffroy.zorbscity.client.GwtLauncher.java
jonathan.geoffroy.zorbscity.model.City.java
jonathan.geoffroy.zorbscity.model.Galaxy.java
jonathan.geoffroy.zorbscity.model.SimulatorEvent.java
jonathan.geoffroy.zorbscity.model.Simulator.java
jonathan.geoffroy.zorbscity.model.TimeLine.java
jonathan.geoffroy.zorbscity.model.cityObjects.buildings.Building.java
jonathan.geoffroy.zorbscity.model.cityObjects.buildings.Construction.java
jonathan.geoffroy.zorbscity.model.cityObjects.buildings.Enterprise.java
jonathan.geoffroy.zorbscity.model.cityObjects.buildings.House.java
jonathan.geoffroy.zorbscity.model.cityObjects.buildings.Road.java
jonathan.geoffroy.zorbscity.model.cityObjects.buildings.Storage.java
jonathan.geoffroy.zorbscity.model.cityObjects.buildings.Structure.java
jonathan.geoffroy.zorbscity.model.cityObjects.buildings.enterprises.ClothesFactory.java
jonathan.geoffroy.zorbscity.model.cityObjects.buildings.enterprises.PowerHouse.java
jonathan.geoffroy.zorbscity.model.cityObjects.buildings.houses.FreeHouse.java
jonathan.geoffroy.zorbscity.model.cityObjects.buildings.houses.SimpleHouse.java
jonathan.geoffroy.zorbscity.model.cityObjects.buildings.houses.TentHouse.java
jonathan.geoffroy.zorbscity.model.cityObjects.buildings.storages.FoodStorage.java
jonathan.geoffroy.zorbscity.model.cityObjects.buildings.storages.SecondaryStorage.java
jonathan.geoffroy.zorbscity.model.cityObjects.people.DeliveryMan.java
jonathan.geoffroy.zorbscity.model.cityObjects.people.Person.java
jonathan.geoffroy.zorbscity.model.cityObjects.resources.Cloth.java
jonathan.geoffroy.zorbscity.model.cityObjects.resources.Power.java
jonathan.geoffroy.zorbscity.model.cityObjects.resources.Resource.java
jonathan.geoffroy.zorbscity.model.cityObjects.resources.Wheat.java
jonathan.geoffroy.zorbscity.model.cityObjects.resources.Wool.java
jonathan.geoffroy.zorbscity.model.helpers.Coord2D.java
jonathan.geoffroy.zorbscity.model.helpers.NeededList.java
jonathan.geoffroy.zorbscity.model.helpers.ResourcesList.java
jonathan.geoffroy.zorbscity.model.simulator.events.ConsumeNeededResources.java
jonathan.geoffroy.zorbscity.model.simulator.events.ObjectCreatedEvent.java
jonathan.geoffroy.zorbscity.model.simulator.events.WeaknessEvent.java
jonathan.geoffroy.zorbscity.view.CityView.java
jonathan.geoffroy.zorbscity.view.shell.CityShellView.java