Packagecom.whirled.contrib.card
Classpublic class Card

Represents a card for use with game logic, rendering and UI. Has suit, rank and all constants for a normal deck. Also provides translation to and from "ordinal" cards for use in serialization. TODO: jokers



Public Properties
 PropertyDefined by
  faceDown : Boolean
[read-only] Access whether the card is face down or not.
Card
  ordinal : int
[read-only] Access the ordinal.
Card
  rank : int
[read-only] Access the rank.
Card
  string : String
[read-only] Get a unique string representation of this card for debugging or naming conventions.
Card
  suit : int
[read-only] Access the suit.
Card
Protected Properties
 PropertyDefined by
  _ordinal : int
The rank (3 high bits) and suit (5 low bits).
Card
Public Methods
 MethodDefined by
  
Card(suit:int, rank:int)
Create a new card.
Card
  
compareRanks(rank1:int, rank2:int, ordering:int):int
[static] Compare two ranks in the given ordering.
Card
  
[static] Create a new Card object from an ordinal.
Card
  
[static] Create a new face down card.
Card
  
equals(rhs:Card):Boolean
Compare for eqaulity to another card.
Card
  
isBetterRank(rhs:Card, ordering:int):Boolean
Check if this card has a better rank than the other.
Card
  
rankString(rank:int):String
[static] Return a short string for a RANK_constant for use in debugging or naming conventions.
Card
  
suitString(suit:int):String
[static] Return a short string for a SUIT_constant for use in debugging or naming conventions.
Card
  
toString():String
Card
Protected Methods
 MethodDefined by
  
validate(type:String, value:int, num:int):void
[static] Throw an exception if the value is less than zero or larger than max.
Card
Public Constants
 ConstantDefined by
  MAX_ORDINAL : int = 255
[static] Number or ordinals.
Card
  MAX_RANK : int = 31
[static] Maximum rank value.
Card
  MAX_SUIT : int = 7
[static] Number of suits.
Card
  NUM_RANK_ORDERS : int = 2
[static] Number of ranks.
Card
  RANK_ACE : int = 0
[static] Constant for the rank of ace.
Card
  RANK_EIGHT : int = 7
[static] Constant for the rank of eight.
Card
  RANK_FIVE : int = 4
[static] Constant for the rank of five.
Card
  RANK_FOUR : int = 3
[static] Constant for the rank of four.
Card
  RANK_JACK : int = 10
[static] Constant for the rank of jack.
Card
  RANK_KING : int = 12
[static] Constant for the rank of king.
Card
  RANK_NINE : int = 8
[static] Constant for the rank of nine.
Card
  RANK_ORDER_ACES_HIGH : int = 1
[static] Constant for aces high rank ordering.
Card
  RANK_ORDER_NORMAL : int = 0
[static] Constant for straight rank ordering.
Card
  RANK_QUEEN : int = 11
[static] Constant for the rank of queen.
Card
  RANKS : Array
[static]
Card
  RANK_SEVEN : int = 6
[static] Constant for the rank of seven.
Card
  RANK_SIX : int = 5
[static] Constant for the rank of six.
Card
  RANK_TEN : int = 9
[static] Constant for the rank of ten.
Card
  RANK_THREE : int = 2
[static] Constant for the rank of three.
Card
  RANK_TWO : int = 1
[static] Constant for the rank of deuce.
Card
  SPRITE_HEIGHT : int = 100
[static] Placeholder value for the height of a card sprite.
Card
  SPRITE_WIDTH : int = 70
[static] Placeholder value for the width of a card sprite.
Card
  SUIT_CLUBS : int = 2
[static] Constant for the suit of clubs.
Card
  SUIT_DIAMONDS : int = 3
[static] Constant for the suit of diamonds.
Card
  SUIT_HEARTS : int = 0
[static] Constant for the suit of hearts.
Card
  SUITS : Array
[static] Array of standard suits.
Card
  SUIT_SPADES : int = 1
[static] Constant for the suit of spades.
Card
Property detail
faceDownproperty
faceDown:Boolean  [read-only]

Access whether the card is face down or not.

Implementation
    public function get faceDown():Boolean
_ordinalproperty 
protected var _ordinal:int

The rank (3 high bits) and suit (5 low bits).

ordinalproperty 
ordinal:int  [read-only]

Access the ordinal.

Implementation
    public function get ordinal():int
rankproperty 
rank:int  [read-only]

Access the rank.

Implementation
    public function get rank():int
stringproperty 
string:String  [read-only]

Get a unique string representation of this card for debugging or naming conventions. E.g. "two of hearts" is "2H".

Implementation
    public function get string():String
suitproperty 
suit:int  [read-only]

Access the suit.

Implementation
    public function get suit():int
Constructor detail
Card()constructor
public function Card(suit:int, rank:int)

Create a new card.

Parameters
suit:int — the suit of the card (one of the SUIT_constants)
 
rank:int — the rank of the card (one of the RANK_constants)

Throws
— if the suit or rank is invalid.
Method detail
compareRanks()method
public static function compareRanks(rank1:int, rank2:int, ordering:int):int

Compare two ranks in the given ordering.

Parameters
rank1:int — the first rank to compare, one of the RANK_constants
 
rank2:int — the second rank to compare, one of the RANK_constants
 
ordering:int — how to compare, one of the RANK_ORDER_constants

Returns
int — a negative number if rank1 < rank2, positive if rank1 > rank2 and zero if rank1 == rank2

Throws
— if any constant is not in the predefined set
createCardFromOrdinal()method 
public static function createCardFromOrdinal(ordinal:int):Card

Create a new Card object from an ordinal.

Parameters
ordinal:int

Returns
Card

Throws
— if the ordinal is not valid.
createFaceDownCard()method 
public static function createFaceDownCard():Card

Create a new face down card. A face down card usually means that the local player "has" the card but cannot yet see its value, i.e. the value is not known.

Returns
Card
equals()method 
public function equals(rhs:Card):Boolean

Compare for eqaulity to another card.

Parameters
rhs:Card

Returns
Boolean — true if the this is equal to the other card
isBetterRank()method 
public function isBetterRank(rhs:Card, ordering:int):Boolean

Check if this card has a better rank than the other.

Parameters
rhs:Card — how to compare, one of the RANK_ORDER_constants
 
ordering:int — card to compare against

Returns
Boolean
rankString()method 
public static function rankString(rank:int):String

Return a short string for a RANK_constant for use in debugging or naming conventions. For example, RANK_ACE is "A". If the rank is not one defined by this class, the string is calculated from the numeric value.

Parameters
rank:int

Returns
String
suitString()method 
public static function suitString(suit:int):String

Return a short string for a SUIT_constant for use in debugging or naming conventions. For example, SUIT_HEARTS is "H". If the suit is not one defined in this class, the string is calcualted from the numeric value.

Parameters
suit:int

Returns
String
toString()method 
public function toString():String

Returns
String
validate()method 
protected static function validate(type:String, value:int, num:int):void

Throw an exception if the value is less than zero or larger than max.

Parameters
type:String — the ordinal name of the value set
 
value:int
 
num:int
Constant detail
MAX_ORDINALconstant
public static const MAX_ORDINAL:int = 255

Number or ordinals. NOTE: also used as a bit mask

MAX_RANKconstant 
public static const MAX_RANK:int = 31

Maximum rank value. NOTE: also used as a bit mask.

MAX_SUITconstant 
public static const MAX_SUIT:int = 7

Number of suits. NOTE: also used as a bit mask.

NUM_RANK_ORDERSconstant 
public static const NUM_RANK_ORDERS:int = 2

Number of ranks.

RANK_ACEconstant 
public static const RANK_ACE:int = 0

Constant for the rank of ace.

RANK_EIGHTconstant 
public static const RANK_EIGHT:int = 7

Constant for the rank of eight.

RANK_FIVEconstant 
public static const RANK_FIVE:int = 4

Constant for the rank of five.

RANK_FOURconstant 
public static const RANK_FOUR:int = 3

Constant for the rank of four.

RANK_JACKconstant 
public static const RANK_JACK:int = 10

Constant for the rank of jack.

RANK_KINGconstant 
public static const RANK_KING:int = 12

Constant for the rank of king.

RANK_NINEconstant 
public static const RANK_NINE:int = 8

Constant for the rank of nine.

RANK_ORDER_ACES_HIGHconstant 
public static const RANK_ORDER_ACES_HIGH:int = 1

Constant for aces high rank ordering.

RANK_ORDER_NORMALconstant 
public static const RANK_ORDER_NORMAL:int = 0

Constant for straight rank ordering.

RANK_QUEENconstant 
public static const RANK_QUEEN:int = 11

Constant for the rank of queen.

RANKSconstant 
public static const RANKS:Array
RANK_SEVENconstant 
public static const RANK_SEVEN:int = 6

Constant for the rank of seven.

RANK_SIXconstant 
public static const RANK_SIX:int = 5

Constant for the rank of six.

RANK_TENconstant 
public static const RANK_TEN:int = 9

Constant for the rank of ten.

RANK_THREEconstant 
public static const RANK_THREE:int = 2

Constant for the rank of three.

RANK_TWOconstant 
public static const RANK_TWO:int = 1

Constant for the rank of deuce.

SPRITE_HEIGHTconstant 
public static const SPRITE_HEIGHT:int = 100

Placeholder value for the height of a card sprite.

SPRITE_WIDTHconstant 
public static const SPRITE_WIDTH:int = 70

Placeholder value for the width of a card sprite.

SUIT_CLUBSconstant 
public static const SUIT_CLUBS:int = 2

Constant for the suit of clubs.

SUIT_DIAMONDSconstant 
public static const SUIT_DIAMONDS:int = 3

Constant for the suit of diamonds.

SUIT_HEARTSconstant 
public static const SUIT_HEARTS:int = 0

Constant for the suit of hearts.

SUITSconstant 
public static const SUITS:Array

Array of standard suits.

SUIT_SPADESconstant 
public static const SUIT_SPADES:int = 1

Constant for the suit of spades.