public class Resource extends Object
Example:
final Resource gold = new Resource(); gold.add(100); gold.get(); // returns 100 gold.canSpend(25); // returns true gold.spend(25); // returns 75 gold.canSpend(100); // returns false
Constructor and Description |
---|
Resource()
Constructor.
|
Resource(int amount)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
int |
add(int amount)
Increase resource stock with a specified amount.
|
boolean |
canSpend(int amount)
Check if the specified amount of resource can be spent.
|
int |
get()
Get current amount of resource.
|
void |
spend(int amount)
Decrease resource stock with a specified amount.
|
public Resource()
public Resource(int amount)
amount
- The starting amount.public int add(int amount)
amount
- The amount of new resource.public void spend(int amount)
canSpend(int)
if you expect only positive values.amount
- The amount of resource to spend.public boolean canSpend(int amount)
amount
- The amount to check.true
if current stock - amount > 0, false
else.public int get()
Copyright © 2014 Byron 3D Games Studio. All rights reserved.