Packagecom.whirled.contrib.card
Classpublic class CardArray
InheritanceCardArray Inheritance flash.events.EventDispatcher

An ordered container of cards with event dispatching. Maintains consistency between an array of ordinals (integers) for use in serialization and an array of Card objects for rendering and game logic. Dispatches CardArrayEvent objects when changes occur. May be extended as needed for use in spades and other card games.



Public Properties
 PropertyDefined by
  cards : Array
[read-only] Access the underlying array of card objects.
CardArray
  length : int
[read-only] Access to the length of the array.
CardArray
  ordinals : Array
[read-only] Access the underlying array of ordinal values.
CardArray
Protected Properties
 PropertyDefined by
  _cards : Array
The Card objects.
CardArray
  _ordinals : Array
The ordinals.
CardArray
Public Methods
 MethodDefined by
  
CardArray(ordinals:Array = null)
Create a new array of cards.
CardArray
  
filter(callback:Function):CardArray
Returns a new CardArray consisting of the contents of this array for which the given callback evaluates to true.
CardArray
  
has(card:Card):Boolean
Test if a card (of the same value) is in the array
CardArray
  
indexOf(card:Card):int
Get the index of a card in the array, or -1 if not present.
CardArray
  
insert(card:Card, index:int):void
Insert a new card into the array.
CardArray
  
[static] Create a new full deck.
CardArray
  
push(card:Card):void
Add a new card to the end.
CardArray
  
pushOrdinal(ordinal:int):void
Add a new card to the end by ordinal value.
CardArray
  
remove(card:Card):void
Remove a card from the array.
CardArray
  
reset(ordinals:Array = null):void
Reset the contents of the array.
CardArray
  
shortFilter(callback:Function):CardArray
Returns a new CardArray consisting of the contents of this array for which the given callback evaluates to true.
CardArray
  
sortedInsert(card:Card, suits:Array, ordering:int):void
Insert a card into the array such that sorting is maintained.
CardArray
  
standardSort(suits:Array, ordering:int):void
Sort the array in place for player's ease of use.
CardArray
  
toString():String
CardArray
Protected Methods
 MethodDefined by
  
setOrdinals(ordinals:Array):void
Set the ordinal values, no event sending.
CardArray
Property detail
_cardsproperty
protected var _cards:Array

The Card objects.

cardsproperty 
cards:Array  [read-only]

Access the underlying array of card objects.

Implementation
    public function get cards():Array
lengthproperty 
length:int  [read-only]

Access to the length of the array.

Implementation
    public function get length():int
_ordinalsproperty 
protected var _ordinals:Array

The ordinals.

ordinalsproperty 
ordinals:Array  [read-only]

Access the underlying array of ordinal values.

Implementation
    public function get ordinals():Array
Constructor detail
CardArray()constructor
public function CardArray(ordinals:Array = null)

Create a new array of cards.

Parameters
ordinals:Array (default = null) — optional array of ordinal values for initial contents

Throws
— if any contents are not valid.
Method detail
filter()method
public function filter(callback:Function):CardArray

Returns a new CardArray consisting of the contents of this array for which the given callback evaluates to true. The callback should have signature: function callback (card :Card, index :int, array :CardArray) :Boolean For example, the following function will return all queens: function findQueens (array :CardArray) :CardArray { return array.filter( function ( card :Card, index :int, array :CardArray) :Boolean { return card.rank == Card.QUEEN; }); }

Parameters
callback:Function

Returns
CardArray
has()method 
public function has(card:Card):Boolean

Test if a card (of the same value) is in the array

Parameters
card:Card

Returns
Boolean
indexOf()method 
public function indexOf(card:Card):int

Get the index of a card in the array, or -1 if not present.

Parameters
card:Card

Returns
int
insert()method 
public function insert(card:Card, index:int):void

Insert a new card into the array.

Parameters
card:Card
 
index:int
makeDeck()method 
public static function makeDeck():CardArray

Create a new full deck. Users may modify the result.

Returns
CardArray
push()method 
public function push(card:Card):void

Add a new card to the end.

Parameters
card:Card
pushOrdinal()method 
public function pushOrdinal(ordinal:int):void

Add a new card to the end by ordinal value.

Parameters
ordinal:int
remove()method 
public function remove(card:Card):void

Remove a card from the array.

Parameters
card:Card

Throws
— if the card is not present.
reset()method 
public function reset(ordinals:Array = null):void

Reset the contents of the array.

Parameters
ordinals:Array (default = null) — optional array of ordinal values for the new contents

Throws
— if any ordinals are not valid.
setOrdinals()method 
protected function setOrdinals(ordinals:Array):void

Set the ordinal values, no event sending.

Parameters
ordinals:Array
shortFilter()method 
public function shortFilter(callback:Function):CardArray

Returns a new CardArray consisting of the contents of this array for which the given callback evaluates to true. The callback should have signature: function callback (card :Card) :Boolean This is a more terse alternative to the more standard-compliant "filter" method. For example, the following function will return all queens: function findQueens (array :CardArray) :CardArray { return array.filter( function ( card :Card) :Boolean { return card.rank == Card.QUEEN; }); }

Parameters
callback:Function

Returns
CardArray
sortedInsert()method 
public function sortedInsert(card:Card, suits:Array, ordering:int):void

Insert a card into the array such that sorting is maintained. The array must previously be sorted with the same parameters.

Parameters
card:Card — the card to insert
 
suits:Array — an Array of Card.SUIT_constants indicating the desired order of suits
 
ordering:int — one of the Card.RANK_ORDER_constants indicating how to order the ranks
standardSort()method 
public function standardSort(suits:Array, ordering:int):void

Sort the array in place for player's ease of use. Suits are the primary key and ranks secondary.

Parameters
suits:Array — an Array of Card.SUIT_constants indicating the desired order of suits
 
ordering:int — one of the Card.RANK_ORDER_constants indicating how to order the ranks
toString()method 
public override function toString():String

Returns
String