Android Open Source - ZorbsCity Resources List






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.helpers;
/*from   w ww  . ja va 2  s.c om*/
import java.util.ArrayList;

import jonathan.geoffroy.zorbscity.model.cityObjects.resources.Resource;
/**
 * The ResourceList is a special HashMap that contains Resources
 * A ResourceList can deliver & count amount of Resources.
 * It also manager the foods system (mainly by differentiate foods: so you can ask if there it at least 1 kind of food for example).
 * @author Jonathan GEOFFROY
 * @version 0.1
 */
public class ResourcesList extends ArrayList<Resource> {
  public final static int FOOD1_RESOURCE = 0, FOOD2_RESOURCE = 1, FOOD3_RESOURCE = 2, WATER_RESOURCE = 3,// TODO: add each Resource type
      POWER_RESOURCE = 4, CLOTHES_RESOURCE = 5, ENTERTAINMENT_RESOURCE = 6,
      WOOL_RESOURCE = 7;
  //  public final static int FOOD_RESOURCE = 100;
  public final static int NB_RESOURCES = 8;
  public static final int MAX_FOOD_NUMBER = 3;
  /**
   * Generated serial default (using eclipse IDE)
   */
  private static final long serialVersionUID = 4692124720616702433L;

  public ResourcesList() {
    super();
  }

  public ResourcesList(int initialCapacity) {
    super(initialCapacity);
  }

  /**
   * 
   * @return true if there are at least 1 amount of each Resource in resources list
   */
  public boolean enoughResources(NeededList neededList) {
    int needed[] = neededList.getNeeded();
    for(int i = 0; i < needed.length; i++) {
      if(!enoughResources(neededList, i)) {
        return false;
      }
    }
    return true;
  }

  /**
   * check if this Building have enough resources of r
   * @param resourceType the type of the resource to check
   * @return true if the resource type is not in the needed list, or return amountNeeded(r)
   */
  public boolean enoughResources(NeededList nl, int resourceType) {
    int needed[] = nl.getNeeded();
    int amountNeeded = needed[resourceType];
    if(amountNeeded == 0) {
      return true;
    }

    Resource r = get(resourceType);
    if(r == null) {
      return false;
    }

    return r.getAmount() >= amountNeeded;
  }

  @Override
  public Resource get(int resourceType) {
    assert(resourceType >= 0 && resourceType< NB_RESOURCES);
    for(Resource r : this) {
      if(r.equals(resourceType)) {
        return r;
      }
    }
    return null;
  }

  /**
   * Decrement the number of needed amount for each needed resource
   * enoughResource() must be true
   */
  public void useNeeded(NeededList nl) {
    assert(enoughResources(nl));
    int needed[] = nl.getNeeded();
    for(int i = 0; i < needed.length; i++) {
      if(needed[i] != 0) {
        get(i).rmAmount(needed[i]);
        assert(get(i).getAmount() >= 0);
      }
    }
  }

  /**
   * @param resourceType
   * @return the stocked amount of <resourceType>
   */
  public int getAmountOf(int resourceType) {
    Resource r = get(resourceType);
    if(r != null) {
      return r.getAmount();
    }
    return 0;
  }
}




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