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; //from w w w . j a v a 2s.c o m import jonathan.geoffroy.zorbscity.model.cityObjects.resources.Resource; import jonathan.geoffroy.zorbscity.model.helpers.ResourcesList; public abstract class Storage extends Construction { Resource resources[]; /** * Auto-generated serial (using eclipse) */ private static final long serialVersionUID = 1141655801387214928L; public Storage() { super(); resources = new Resource[ResourcesList.NB_RESOURCES]; } /** * Add the resource into the Deposit * If it isn't enough getSpace(), don't add nothing and return false * @param r the resource to add * @return true if the resource have been added, false otherwise */ public boolean add(Resource r) { if(canAdd(r)) { int resourceType = r.getResourceNumber(); Resource into = resources[resourceType]; if(into == null) { resources[resourceType] = r; } else { into.addAmount(r.getAmount()); } return true; } return false; } /** * return the sum of amounts of all resources stocked into this Deposit */ public int size() { int size = 0; for(Resource r : resources) { if(r != null) { size += r.getAmount(); } } assert(size <= getSpace()); return size; } /** * * @return the free getSpace() */ public int freeSpace() { assert(getSpace() - size() >= 0); return getSpace() - size(); } /** * * @param r * @return true if <r> can can be fully stored into this Deposit */ public boolean canAdd(Resource r) { return getSpace() >= size() + r.getAmount(); } public abstract int getSpace(); }