|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectsoc.game.SOCResourceSet
This represents a collection of clay, ore, sheep, wheat, and wood resources. Unknown resources are also tracked here. Although it's possible to store negative amounts of resources, it's discouraged.
| Field Summary | |
static SOCResourceSet |
EMPTY_SET
Resource set with zero of each resource type |
private int[] |
resources
the number of resources |
| Constructor Summary | |
SOCResourceSet()
Make an empty resource set |
|
SOCResourceSet(int cl,
int or,
int sh,
int wh,
int wo,
int uk)
Make a resource set with stuff in it |
|
| Method Summary | |
void |
add(int amt,
int rtype)
add an amount to a resource |
void |
add(SOCResourceSet rs)
add an entire resource set's amounts into this set. |
void |
clear()
set the number of resources to zero |
boolean |
contains(SOCResourceSet sub)
|
void |
convertToUnknown()
Convert all these resources to type SOCResourceConstants.UNKNOWN. |
SOCResourceSet |
copy()
|
boolean |
equals(java.lang.Object anObject)
|
int |
getAmount(int rtype)
|
int |
getTotal()
|
static boolean |
gte(SOCResourceSet a,
SOCResourceSet b)
|
int |
hashCode()
|
static boolean |
lte(SOCResourceSet a,
SOCResourceSet b)
|
void |
setAmount(int amt,
int rtype)
set the amount of a resource |
void |
setAmounts(SOCResourceSet set)
copy a resource set into this one. |
void |
subtract(int amt,
int rtype)
subtract an amount from a resource. |
void |
subtract(SOCResourceSet rs)
subtract an entire resource set. |
java.lang.String |
toFriendlyString()
Human-readable form of the set, with format "5 clay,1 ore,3 wood" |
boolean |
toFriendlyString(java.lang.StringBuffer sb)
Human-readable form of the set, with format "5 clay, 1 ore, 3 wood" |
java.lang.String |
toShortString()
Human-readable form of the set, with format "Resources: 5 1 0 0 3 0". |
java.lang.String |
toString()
Human-readable form of the set, with format "clay=5|ore=1|sheep=0|wheat=0|wood=3|unknown=0" |
| Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
public static final SOCResourceSet EMPTY_SET
private int[] resources
| Constructor Detail |
public SOCResourceSet()
public SOCResourceSet(int cl,
int or,
int sh,
int wh,
int wo,
int uk)
cl - number of clay resourcesor - number of ore resourcessh - number of sheep resourceswh - number of wheat resourceswo - number of wood resourcesuk - number of unknown resources| Method Detail |
public void clear()
public int getAmount(int rtype)
rtype - the type of resource, like SOCResourceConstants.CLAY
public int getTotal()
public void setAmount(int amt,
int rtype)
rtype - the type of resource, like SOCResourceConstants.CLAYamt - the amount
public void add(int amt,
int rtype)
rtype - the type of resource, like SOCResourceConstants.CLAYamt - the amount; if below 0 (thus subtracting resources),
the subtraction occurs and no special action is taken.
subtract(int, int) takes special action in some cases.
public void subtract(int amt,
int rtype)
SOCResourceConstants.UNKNOWN resources.
As a result, UNKNOWN may be less than zero afterwards.
rtype - the type of resource, like SOCResourceConstants.CLAYamt - the amount; unlike in add(int, int), any amount that
takes the resource below 0 is treated specially.public void add(SOCResourceSet rs)
rs - the resource setpublic void subtract(SOCResourceSet rs)
rs - the resource setpublic void convertToUnknown()
SOCResourceConstants.UNKNOWN.
Information on amount of wood, wheat, etc is no longer available.
Equivalent to:
int numTotal = resSet.getTotal();
resSet.clear();
resSet.setAmount (SOCResourceConstants.UNKNOWN, numTotal);
public static boolean gte(SOCResourceSet a,
SOCResourceSet b)
a - set Ab - set B
public static boolean lte(SOCResourceSet a,
SOCResourceSet b)
a - set Ab - set B
public java.lang.String toString()
toShortString(),
toFriendlyString()public java.lang.String toShortString()
toFriendlyString()public java.lang.String toFriendlyString()
toShortString()public boolean toFriendlyString(java.lang.StringBuffer sb)
sb - Append into this buffer.
toFriendlyString()public boolean contains(SOCResourceSet sub)
sub - the sub set
public boolean equals(java.lang.Object anObject)
anObject - the object in question
public int hashCode()
public SOCResourceSet copy()
public void setAmounts(SOCResourceSet set)
set - the set to copy from
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||