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.resources; //from w ww.ja v a2 s. c o m import java.io.Serializable; /** * Resource in a city * Each Resource has a type, according to it real class. * A resource equals (at java equals(o) way) if both have the same class * @author Jonathan GEOFFROY * @version 0.1 */ public abstract class Resource implements Serializable { public static final int COMMON_CREATED_AMOUNT = 80, COMMON_NEEDED_AMOUNT = 40; /** * auto-generated serial (using eclipse) */ private static final long serialVersionUID = 1633406054007907709L; /** * The amount of the resource * should be positive (or null if the resource was here but disappeared) */ private int amount; /** * Instantiate a new Resource with 0 amount */ public Resource() { amount = COMMON_CREATED_AMOUNT; } /** * Instantiate a new Resource with the amount passed in parameter * amount should be >= 0 * @param amount */ public Resource(int amount) { assert(amount >= 0); this.amount = amount; } public int getAmount() { return amount; } public void setAmount(int amount) { this.amount = amount; } public void addAmount(int amount) { this.amount += amount; } public void rmAmount(int amount) { assert(this.amount >= amount) : "There are no enough amount!"; this.amount -= amount; } @Override public boolean equals(Object obj) { if(obj instanceof Integer) { Integer i = (Integer) obj; return i == getResourceNumber(); } return this.getClass().equals(obj.getClass()); } public abstract String getName(); public abstract int getResourceNumber(); }