|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object soc.game.SOCInventory
public class SOCInventory
This represents a collection of development cards, and occasional scenario-specific items. Players can have 0, 1, or more of any card type or item type. Each item's current state can be New to be played soon; Playable; or Kept in hand until the end of the game (Victory Point cards, which are never New).
For use in loops, age constants and inventory-item state constant ranges are each contiguous:
OLD
== 0, NEW
== 1.
NEW
== 1, PLAYABLE
== 2, KEPT
== 3.
Before v2.0.00, this class was named SOCDevCardSet
.
Field Summary | |
---|---|
private java.util.List<SOCInventoryItem> |
kept
Current set of the items having 1 of 3 possible states (New and not playable yet; Playable; Kept until end of game). |
static int |
KEPT
Item state constant: Kept in hand until end of game (not PLAYABLE , was never NEW ). |
static int |
NEW
Age constant, item state constant: Recently bought card, playable next turn. Other possible age is OLD .Other possible states are PLAYABLE and KEPT . |
private java.util.List<SOCInventoryItem> |
news
Current set of the items having 1 of 3 possible states (New and not playable yet; Playable; Kept until end of game). |
static int |
OLD
Age constant: An old item can either be played this turn (state PLAYABLE )
or is kept in hand until the end of the game (state KEPT ) such as a Victory Point card. |
static int |
PLAYABLE
Item state constant: Playable this turn (not NEW or KEPT ). |
private java.util.List<SOCInventoryItem> |
playables
Current set of the items having 1 of 3 possible states (New and not playable yet; Playable; Kept until end of game). |
Constructor Summary | |
---|---|
SOCInventory()
Make an empty dev card and inventory item set. |
|
SOCInventory(SOCInventory set)
Make a copy of a dev card and inventory item set. |
Method Summary | |
---|---|
void |
addDevCard(int amt,
int age,
int ctype)
Add an amount to a type of dev card. |
void |
addItem(SOCInventoryItem item)
Add a special item or dev card to this set. |
void |
clear()
set the total number of dev cards to zero |
int |
getAmount(int ctype)
Get the amount of a dev card type or special item in the set. |
int |
getAmount(int age,
int ctype)
Get the amount of a dev card type of certain age in the set. |
int |
getAmountByState(int state,
int itype)
Get the amount of dev cards or special items by state and type. |
java.util.List<SOCInventoryItem> |
getByState(int cState)
Get the cards and items, if any, having this state. |
int |
getNumUnplayed()
Some card types stay in your hand after being played. |
int |
getNumVPItems()
Get the number of Victory Point cards and VP items in this set: All cards and items returning true for SOCInventoryItem.isVPItem() . |
int |
getTotal()
|
boolean |
hasPlayable(int ctype)
Does this set contain 1 or more playable cards or items of this type? (Playable this turn: Not new, not already played and then kept.) |
boolean |
keepPlayedItem(int itype)
Keep a played item: Change its state from PLAYABLE to KEPT . |
void |
newToOld()
Change all the new cards and items to old ones. |
void |
removeDevCard(int age,
int ctype)
Remove one dev card of a type from the set. |
SOCInventoryItem |
removeItem(int state,
int itype)
Remove a special item or card with a certain state from this set. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int OLD
PLAYABLE
)
or is kept in hand until the end of the game (state KEPT
) such as a Victory Point card.
public static final int NEW
OLD
.PLAYABLE
and KEPT
.
public static final int PLAYABLE
NEW
or KEPT
).
public static final int KEPT
PLAYABLE
, was never NEW
).
private final java.util.List<SOCInventoryItem> news
SOCDevCard.isVPCard(ctype)
it is placed in kept
,
never in news
.
This implementation assumes players will have only a few cards or items at a time, so linear searching for a
SOCInventoryItem.itype
type is acceptable.
private final java.util.List<SOCInventoryItem> playables
SOCDevCard.isVPCard(ctype)
it is placed in kept
,
never in news
.
This implementation assumes players will have only a few cards or items at a time, so linear searching for a
SOCInventoryItem.itype
type is acceptable.
private final java.util.List<SOCInventoryItem> kept
SOCDevCard.isVPCard(ctype)
it is placed in kept
,
never in news
.
This implementation assumes players will have only a few cards or items at a time, so linear searching for a
SOCInventoryItem.itype
type is acceptable.
Constructor Detail |
---|
public SOCInventory()
public SOCInventory(SOCInventory set) throws java.lang.CloneNotSupportedException
SOCDevCard
/SOCInventoryItem
objects are cloned.
set
- the inventory set to copy
java.lang.CloneNotSupportedException
- Should not occur; SOCInventoryItem
s should be CloneableMethod Detail |
---|
public void clear()
public java.util.List<SOCInventoryItem> getByState(int cState) throws java.lang.IllegalArgumentException
cState
- Card/item state: NEW
, PLAYABLE
or KEPT
java.lang.IllegalArgumentException
- if cState
isn't one of the 3 item stateshasPlayable(int)
public boolean hasPlayable(int ctype)
ctype
- Type of development card from SOCDevCardConstants
, or item type
from SOCInventoryItem.itype
getByState(int)
public int getAmount(int ctype)
ctype
- Type of development card or item as described
in SOCDevCardConstants
and SOCInventoryItem.itype
getAmount(int, int)
,
getAmountByState(int, int)
public int getAmount(int age, int ctype)
SOCDevCard
.
age
- either OLD
or NEW
ctype
- the type of development card as described in SOCDevCardConstants
getAmount(int)
,
getAmountByState(int, int)
,
hasPlayable(int)
,
getByState(int)
public int getAmountByState(int state, int itype) throws java.lang.IllegalArgumentException
state
- NEW
, PLAYABLE
, or KEPT
itype
- Item type code, from SOCInventoryItem.itype
or SOCDevCardConstants
java.lang.IllegalArgumentException
- if state
isn't one of the 3 item statesgetAmount(int, int)
public int getTotal()
getNumUnplayed()
,
getNumVPItems()
public void addItem(SOCInventoryItem item)
The item's SOCInventoryItem.isPlayable()
or/and SOCInventoryItem.isKept()
will be called to determine its initial state:
item.isPlayable()
-> PLAYABLE
item.isKept()
-> KEPT
NEW
item
- The special item or dev card being addedaddDevCard(int, int, int)
,
removeItem(int, int)
,
keepPlayedItem(int)
public void addDevCard(int amt, int age, int ctype)
KEPT
. Otherwise, cards with age
== OLD
will have state PLAYABLE
, new cards will have NEW
.
Before v2.0.00, this method was add(amt, age, ctype)
.
age
- either OLD
or NEW
ctype
- the type of development card, at least
SOCDevCardConstants.MIN
and less than SOCDevCardConstants.MAXPLUSONE
amt
- the amountaddItem(SOCInventoryItem)
,
removeDevCard(int, int)
public boolean keepPlayedItem(int itype)
PLAYABLE
to KEPT
.
itype
- Item type code from SOCInventoryItem.itype
public SOCInventoryItem removeItem(int state, int itype) throws java.lang.IllegalArgumentException
SOCDevCardConstants.UNKNOWN
instead.
state
- Item state: NEW
, PLAYABLE
or KEPT
itype
- Item type code from SOCInventoryItem.itype
,
or card type from SOCDevCardConstants
null
if not found
java.lang.IllegalArgumentException
- if state
isn't one of the 3 item statesremoveDevCard(int, int)
,
keepPlayedItem(int)
public void removeDevCard(int age, int ctype)
SOCDevCardConstants.UNKNOWN
instead.
Before v2.0.00, this method was subtract(amt, age, ctype)
.
age
- either OLD
or NEW
ctype
- the type of development card, at least
SOCDevCardConstants.MIN
and less than SOCDevCardConstants.MAXPLUSONE
removeItem(int, int)
public int getNumVPItems()
SOCInventoryItem.isVPItem()
.
Before v2.0.00, this was getNumVPCards()
.
getNumUnplayed()
,
getTotal()
,
getByState(int)
,
SOCDevCard.isVPCard(int)
public int getNumUnplayed()
getNumVPItems()
,
getTotal()
,
getByState(int)
public void newToOld()
NEW
becomes PLAYABLE
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |