Packagecom.whirled.contrib.card
Classpublic class Hand
InheritanceHand Inheritance flash.events.EventDispatcher

Represents the local player's hand in a card game. Provides facilities for dealing, playing and passing cards. Currently oriented mostly towards trick taking games. TODO: support more non-trick-taking game features like discarding, drawing and dealing a fixed number of cards



Public Properties
 PropertyDefined by
  cards : CardArray
[read-only] Access the underlying array of cards.
Hand
  hasPlayed : Boolean
[read-only] Access whether or not some cards have been selected since the last call to beginTurn.
Hand
  isPassing : Boolean
[read-only] Access whether the local player is currently passing.
Hand
  length : int
[read-only] Access the number of cards in the hand.
Hand
  passCount : int
[read-only] Access the numr of cards requested to be passed by the local player.
Hand
  passTarget : int
[read-only] Access the target player for the local player's pass in progress.
Hand
Protected Properties
 PropertyDefined by
  _cards : CardArray
Hand
  _gameCtrl : GameControl
Hand
  _hasPlayed : Boolean
Hand
  _passCount : int
Hand
  _passTarget : int
Hand
  _prefix : String
Hand
  _sorter : Sorter
Hand
Public Methods
 MethodDefined by
  
Hand(gameCtrl:GameControl, sorter:Sorter, prefix:String = null)
Create a new hand.
Hand
  
allowPlay(enabled:CardArray, count:int = 1):void
Allow the local player to play some cards from a given allowed set.
Hand
  
allowSelection(enabled:CardArray, count:int = 1):void
Allow the selection of cards, but not actually playing them.
Hand
  
dealFaceDownTo(id:int, numCards:int):void
Add some face down cards to a given player.
Hand
  
dealTo(playerId:int, numCards:int):void
Deal from the server's deck to one player.
Hand
  
Disallow card selection, typically called when it is no longer the player's turn and there is no reasonable selection he or she could make.
Hand
  
passCards(cards:CardArray):void
Pass the given cards to fulfill a pass request.
Hand
  
playCard(card:Card):void
Play a single card.
Hand
  
playCards(cards:CardArray):void
Select some cards to play.
Hand
  
prepare(deck:CardArray):void
Reset the deck on the server to the given deck.
Hand
  
prepareAndDeal(deck:CardArray, numCards:int):void
Deal the given deck to all players, giving each player the same number of cards.
Hand
  
removeCard(card:Card):void
Remove a single card from the hand.
Hand
  
removeCards(cards:CardArray):void
Remove cards from the hand.
Hand
  
requestPass(fromPlayer:int, toPlayer:int, numCards:int):void
Request that one player pass some cards to another player.
Hand
Protected Methods
 MethodDefined by
  
handleMessage(event:MessageReceivedEvent):void
Hand
  
varName(name:String):String
Hand
Protected Constants
 ConstantDefined by
  DEALT : String = "hand.dealt"
[static] Event message for getting cards.
Hand
  DEALT_FACE_DOWN : String = "hand.dealt.face.down"
[static] Event message for getting face down cards.
Hand
  DECK : String = "hand.deck"
[static] Name of bag for the deck.
Hand
  PASS_FULFILL : String = "hand.pass.fulfill"
[static] Event message for receiving passed cards.
Hand
  PASS_NOTIFY : String = "hand.pass.notify"
[static] Event message for notifying other players of the pass.
Hand
  PASS_REQUEST : String = "hand.pass.request"
[static] Event message for receiving the pass request.
Hand
Property detail
_cardsproperty
protected var _cards:CardArray
cardsproperty 
cards:CardArray  [read-only]

Access the underlying array of cards. The caller MUST NOT modify the array directly.

Implementation
    public function get cards():CardArray
_gameCtrlproperty 
protected var _gameCtrl:GameControl
_hasPlayedproperty 
protected var _hasPlayed:Boolean
hasPlayedproperty 
hasPlayed:Boolean  [read-only]

Access whether or not some cards have been selected since the last call to beginTurn. This is necessary for the auto-play feature where cards are randomly selected by the controller if the player takes too long to make a move.

Implementation
    public function get hasPlayed():Boolean
isPassingproperty 
isPassing:Boolean  [read-only]

Access whether the local player is currently passing.

Implementation
    public function get isPassing():Boolean
lengthproperty 
length:int  [read-only]

Access the number of cards in the hand.

Implementation
    public function get length():int
_passCountproperty 
protected var _passCount:int
passCountproperty 
passCount:int  [read-only]

Access the numr of cards requested to be passed by the local player. 0 if no pass has been requested.

Implementation
    public function get passCount():int
_passTargetproperty 
protected var _passTarget:int
passTargetproperty 
passTarget:int  [read-only]

Access the target player for the local player's pass in progress. 0 if no pass has been requested.

Implementation
    public function get passTarget():int
_prefixproperty 
protected var _prefix:String
_sorterproperty 
protected var _sorter:Sorter
Constructor detail
Hand()constructor
public function Hand(gameCtrl:GameControl, sorter:Sorter, prefix:String = null)

Create a new hand.

Parameters
gameCtrl:GameControl — the game control to use for table information and for networking
 
sorter:Sorter — the prefix to use for our server variables in case the rules require multiple local hands
 
prefix:String (default = null) — applies an ordering to cards when they are dealt and prior
Method detail
allowPlay()method
public function allowPlay(enabled:CardArray, count:int = 1):void

Allow the local player to play some cards from a given allowed set. This is not a network event and immediately sends HandEvent.BEGAN_TURN.

Parameters
enabled:CardArray
 
count:int (default = 1)
allowSelection()method 
public function allowSelection(enabled:CardArray, count:int = 1):void

Allow the selection of cards, but not actually playing them. This is not a network event and immediately sends HandEvent.ALLOW_SELECT.

Parameters
enabled:CardArray
 
count:int (default = 1)
dealFaceDownTo()method 
public function dealFaceDownTo(id:int, numCards:int):void

Add some face down cards to a given player.

Parameters
id:int
 
numCards:int
dealTo()method 
public function dealTo(playerId:int, numCards:int):void

Deal from the server's deck to one player.

Parameters
playerId:int — the player to deal to
 
numCards:int — number of cards to deal
disallowSelection()method 
public function disallowSelection():void

Disallow card selection, typically called when it is no longer the player's turn and there is no reasonable selection he or she could make. This is not a network event and immediately sends HandEvent.DISALLOWED_SELECTION.

handleMessage()method 
protected function handleMessage(event:MessageReceivedEvent):voidParameters
event:MessageReceivedEvent
passCards()method 
public function passCards(cards:CardArray):void

Pass the given cards to fulfill a pass request. The cards are sent to the pass target using a HandEvent.PASSED event. Other players are also notified via a HandEvent.PASSED event with no cards.

Parameters
cards:CardArray
playCard()method 
public function playCard(card:Card):void

Play a single card. Convenience function to call playCards with a CardArray containing only one card.

Parameters
card:Card
playCards()method 
public function playCards(cards:CardArray):void

Select some cards to play. This is not a network event. It immediately sends a HandEvent.CARDS_PLAYED event.

Parameters
cards:CardArray
prepare()method 
public function prepare(deck:CardArray):void

Reset the deck on the server to the given deck. Note that this method should only be called by one of the players in the game (the one for which GameSubControl.amInControl returns true) or the server agent.

Parameters
deck:CardArray
prepareAndDeal()method 
public function prepareAndDeal(deck:CardArray, numCards:int):void

Deal the given deck to all players, giving each player the same number of cards. Leftover cards will be held on the server. Note that this method should only be called by one of the players in the game (the one for which GameSubControl.amInControl returns true) or the server agent. When the cards arrive to the player, each local hand will dispatch a HandEvent.DEALT message.

Parameters
deck:CardArray — the full deck of cards to store on the server
 
numCards:int — optional number of cards to deal to each player. If 0, cards are dealt evenly TODO: options for what to do with the leftover cards?
removeCard()method 
public function removeCard(card:Card):void

Remove a single card from the hand. Normally the controller will call this in conjunction with another call to place the card elsewhere on the table, return it to the deck, etc. Does not send any events.

Parameters
card:Card
removeCards()method 
public function removeCards(cards:CardArray):void

Remove cards from the hand. Normally the controller will call this in conjunction with another call to place the cards elsewhere on the table, return them to the deck, etc. Does not send any events.

Parameters
cards:CardArray
requestPass()method 
public function requestPass(fromPlayer:int, toPlayer:int, numCards:int):void

Request that one player pass some cards to another player. This will dispatch a HandEvent.PASS_REQUESTED event on the client who perform the pass and set the passTarget property to indicate the target player.

Parameters
fromPlayer:int — the id of the player who is to perform the pass
 
toPlayer:int — the id of the player to receive the passed cards
 
numCards:int — the number of cards to pass
varName()method 
protected function varName(name:String):StringParameters
name:String

Returns
String
Constant detail
DEALTconstant
protected static const DEALT:String = "hand.dealt"

Event message for getting cards.

DEALT_FACE_DOWNconstant 
protected static const DEALT_FACE_DOWN:String = "hand.dealt.face.down"

Event message for getting face down cards.

DECKconstant 
protected static const DECK:String = "hand.deck"

Name of bag for the deck.

PASS_FULFILLconstant 
protected static const PASS_FULFILL:String = "hand.pass.fulfill"

Event message for receiving passed cards.

PASS_NOTIFYconstant 
protected static const PASS_NOTIFY:String = "hand.pass.notify"

Event message for notifying other players of the pass.

PASS_REQUESTconstant 
protected static const PASS_REQUEST:String = "hand.pass.request"

Event message for receiving the pass request.