soc.game
Class SOCDevCard

java.lang.Object
  extended by soc.game.SOCInventoryItem
      extended by soc.game.SOCDevCard
All Implemented Interfaces:
java.lang.Cloneable, SOCDevCardConstants

public class SOCDevCard
extends SOCInventoryItem
implements SOCDevCardConstants

A single Dev Card, probably within a player's SOCInventory.

Since:
2.0.00
Author:
Jeremy D Monin <jeremy@nand.net>

Field Summary
private static java.lang.String[][] GETCARDTYPENAME_KEYS
          Resource type-and-count text keys for getCardTypeName(int, SOCGame, boolean, SOCStringManager).
private  boolean nameKeyPrecalc
          If true, getItemName(SOCGame, boolean, SOCStringManager) can just use the strKey or aStrKey keys already looked up for the constructor super call.
 
Fields inherited from class soc.game.SOCInventoryItem
aStrKey, canCancelPlay, itype, strKey
 
Fields inherited from interface soc.game.SOCDevCardConstants
CAP, DESTROY, DISC, KNIGHT, KNIGHT_FOR_VERS_1_X, LIB, MAXPLUSONE, MIN, MIN_KNOWN, MONO, ROADS, SWAP, TEMP, TOW, UNIV, UNKNOWN, UNKNOWN_FOR_VERS_1_X, VERSION_FOR_NEW_TYPES
 
Constructor Summary
  SOCDevCard(int type, boolean isNew)
          Create a new card.
private SOCDevCard(int type, boolean isVPCard, boolean isNew)
          constructor to call super, to avoid 3 isVPCard(type) calls
 
Method Summary
static java.lang.String getCardTypeName(int ctype, SOCGame game, boolean withArticle, SOCStringManager strings)
          Get a card type's name.
static java.lang.String getCardTypeNameKey(int ctype, SOCGame game, boolean withArticle)
          Get a card type's name key.
 java.lang.String getItemName(SOCGame game, boolean withArticle, SOCStringManager strings)
          Get the item's name.
static boolean isVPCard(int ctype)
          Is this card type a Victory Point card?
 java.lang.String toString()
          Get a human-readable description, including type, isPlayable, isVP.
 
Methods inherited from class soc.game.SOCInventoryItem
clone, createForScenario, isKept, isNew, isPlayable, isPlayForPlacement, isVPItem, newToOld
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

nameKeyPrecalc

private final boolean nameKeyPrecalc
If true, getItemName(SOCGame, boolean, SOCStringManager) can just use the strKey or aStrKey keys already looked up for the constructor super call.

If false, the item text varies by game options and must be calculated each time getItemName(SOCGame, boolean, SOCStringManager) is called.


GETCARDTYPENAME_KEYS

private static final java.lang.String[][] GETCARDTYPENAME_KEYS
Resource type-and-count text keys for getCardTypeName(int, SOCGame, boolean, SOCStringManager). Each subarray's indexes are the same values as SOCDevCardConstants.UNKNOWN to SOCDevCardConstants.TOW.

Constructor Detail

SOCDevCard

public SOCDevCard(int type,
                  boolean isNew)
Create a new card.

Parameters:
type - Card type, such as SOCDevCardConstants.ROADS
isNew - Is this card newly given to a player, or old from a previous turn?

SOCDevCard

private SOCDevCard(int type,
                   boolean isVPCard,
                   boolean isNew)
constructor to call super, to avoid 3 isVPCard(type) calls

Method Detail

isVPCard

public static boolean isVPCard(int ctype)
Is this card type a Victory Point card?

Parameters:
ctype - A constant such as SOCDevCardConstants.TOW or SOCDevCardConstants.ROADS
Returns:
True for VP types, false otherwise
See Also:
SOCInventoryItem.isVPItem()

getCardTypeNameKey

public static java.lang.String getCardTypeNameKey(int ctype,
                                                  SOCGame game,
                                                  boolean withArticle)
Get a card type's name key.

Parameters:
ctype - A constant such as SOCDevCardConstants.TOW or SOCDevCardConstants.ROADS
game - Game data, or null; some game options might change a card name. For example, _SC_PIRI renames "Knight" to "Warship".
withArticle - If true, format is: "a Market (+1VP)"; if false, is "Market (1VP)"
Returns:
The card name key for ctype and withArticle; unknown ctypes return "spec.dcards.unknown" / "spec.dcards.aunknown".
See Also:
getCardTypeName(int, SOCGame, boolean, SOCStringManager)

getCardTypeName

public static java.lang.String getCardTypeName(int ctype,
                                               SOCGame game,
                                               boolean withArticle,
                                               SOCStringManager strings)
Get a card type's name.

Parameters:
ctype - A constant such as SOCDevCardConstants.TOW or SOCDevCardConstants.ROADS
game - Game data, or null; some game options might change a card name. For example, _SC_PIRI renames "Knight" to "Warship".
withArticle - If true, format is: "a Market (+1VP)"; if false, is "Market (1VP)"
strings - StringManager to get i18n localized text
Returns:
The localized card name, formatted per ctype and withArticle; unknown ctypes return "Unknown card type #"
See Also:
getCardTypeNameKey(int, SOCGame, boolean)

toString

public java.lang.String toString()
Get a human-readable description, including type, isPlayable, isVP.

Overrides:
toString in class java.lang.Object
Returns:
String of form: "SOCDevCard{type=__, playable=__, isVP=__}"
Since:
2.0.00

getItemName

public java.lang.String getItemName(SOCGame game,
                                    boolean withArticle,
                                    SOCStringManager strings)
Description copied from class: SOCInventoryItem
Get the item's name.

Called at server and at client, so any i18n name keys used must be in properties files at server and client.

SOCInventoryItem's implementation just calls strings.get(key) with the string keys passed to the constructor. If you need something more dynamic, override this in your subclass.

Overrides:
getItemName in class SOCInventoryItem
Parameters:
game - Game data, or null; some game options might change an item name. For example, _SC_PIRI renames "Knight" to "Warship".
withArticle - If true, format is: "a Market (+1VP)"; if false, is "Market (1VP)"
strings - StringManager to get i18n localized text
Returns:
The localized item name, formatted per withArticle