Back to project page ZorbsCity.
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.
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; } }