Packagecom.whirled.contrib.card.trick
Classpublic class Trick
InheritanceTrick Inheritance flash.events.EventDispatcher

Represents the trick in a trick-taking card game such as spades. Manages communication with the server. Generally when a change is requested to the trick via methods (e.g. playCard), the notification is sent to the server the change is only made after the reply is received, at which time one or more TrickEvent objects are dispatched. Also manages the detection of the trick winner.



Public Properties
 PropertyDefined by
  cards : CardArray
[read-only] Access the underlying array of cards that make up the trick.
Trick
  complete : Boolean
[read-only] Access the flag indicating whether or not the trick is complete.
Trick
  leader : int
[read-only] Access the id of the player that led the trick.
Trick
  ledCard : Card
[read-only] Access the first card played in the trick.
Trick
  length : int
[read-only] Access the number of cards played so far.
Trick
  numPlayers : int
[read-only] Access the number of players.
Trick
  players : Array
[read-only] Access the underyling array of players that have participated in the trick.
Trick
  winner : int
[read-only] Access the winner of the trick.
Trick
Protected Properties
 PropertyDefined by
  _beats : Function
Trick
  _cards : CardArray
Trick
  _gameCtrl : GameControl
Trick
  _numPlayers : int
Trick
  _players : Array
Trick
  _prefix : String
Trick
  _winner : int
Trick
Public Methods
 MethodDefined by
  
Trick(gameCtrl:GameControl, beats:Function, prefix:String = null)
Create a new trick object.
Trick
  
forEach(fn:Function):void
Call a function for each card, player pair.
Trick
  
hasPlayed(playerId:int):Boolean
Tests whether the player with the id has already put a card into the trick.
Trick
  
playCard(card:Card):void
Send a message to the server that the local player has played a card into the trick.
Trick
  
reset():void
Send a message to the server to clear all cards out of the trick.
Trick
Protected Methods
 MethodDefined by
  
Trick
  
handlePropertyChanged(event:PropertyChangedEvent):void
Trick
  
Trick
  
varName(name:String):String
Prefix the name for our instance.
Trick
Protected Constants
 ConstantDefined by
  CARDS : String = "trick.cards"
[static]
Trick
  PLAYERS : String = "trick.players"
[static]
Trick
  SIZE : String = "trick.size"
[static]
Trick
Property detail
_beatsproperty
protected var _beats:Function
_cardsproperty 
protected var _cards:CardArray
cardsproperty 
cards:CardArray  [read-only]

Access the underlying array of cards that make up the trick. The 0th card is always the led card. DO NOT modify the array.

Implementation
    public function get cards():CardArray
completeproperty 
complete:Boolean  [read-only]

Access the flag indicating whether or not the trick is complete. The trick is only complete if all players have played a card.

Implementation
    public function get complete():Boolean
_gameCtrlproperty 
protected var _gameCtrl:GameControl
leaderproperty 
leader:int  [read-only]

Access the id of the player that led the trick. Ths value is 0 if no cards have been played since the trick was reset.

Implementation
    public function get leader():int
ledCardproperty 
ledCard:Card  [read-only]

Access the first card played in the trick. The value is 0 if no cards have been played since the trick was reset.

Implementation
    public function get ledCard():Card
lengthproperty 
length:int  [read-only]

Access the number of cards played so far.

Implementation
    public function get length():int
_numPlayersproperty 
protected var _numPlayers:int
numPlayersproperty 
numPlayers:int  [read-only]

Access the number of players. This determines the maximum size of the trick and also the number of cards that complete the trick.

Implementation
    public function get numPlayers():int
_playersproperty 
protected var _players:Array
playersproperty 
players:Array  [read-only]

Access the underyling array of players that have participated in the trick. The 0th entry is the player that led the trick. DO NOT modify the array.

Implementation
    public function get players():Array
_prefixproperty 
protected var _prefix:String
_winnerproperty 
protected var _winner:int
winnerproperty 
winner:int  [read-only]

Access the winner of the trick. Even if the trick is not complete, the winner is set to the player that would currently win.

Implementation
    public function get winner():int
Constructor detail
Trick()constructor
public function Trick(gameCtrl:GameControl, beats:Function, prefix:String = null)

Create a new trick object.

Parameters
gameCtrl:GameControl — the game control used to listen and send network events that update the trick
 
beats:Function — function to compare two cards. The signature should be: function beats (candidate :Card, winnerSoFar :Card) :Boolean and should return true if the candidate card beats the winner so far and false if it doesn't. Note that the winnerSoFar argument converys information about the led suit.
 
prefix:String (default = null) — the prefix to use for server-side variables in case the client needs to instantiate more than one trick
Method detail
calculateWinner()method
protected function calculateWinner():int

Returns
int
forEach()method 
public function forEach(fn:Function):void

Call a function for each card, player pair. The signature should be: function fn (card :Card, player :int)

Parameters
fn:Function
handlePropertyChanged()method 
protected function handlePropertyChanged(event:PropertyChangedEvent):voidParameters
event:PropertyChangedEvent
hasPlayed()method 
public function hasPlayed(playerId:int):Boolean

Tests whether the player with the id has already put a card into the trick.

Parameters
playerId:int

Returns
Boolean
playCard()method 
public function playCard(card:Card):void

Send a message to the server that the local player has played a card into the trick. When the reply is received, a TrickEvent.CARD_PLAYED event will be dispatched. Then, if the card changes the winner of the trick, a FORERUNNER_CHANGED event is dispatched. Finally, if the card is the final card in the trick, a COMPLETED event is dispatched.

Parameters
card:Card

Throws
— if the trick is already full
reset()method 
public function reset():void

Send a message to the server to clear all cards out of the trick. When the reply is received, a TrickEvent.RESET event will be dispatched.

updateFromServer()method 
protected function updateFromServer():void
varName()method 
protected function varName(name:String):String

Prefix the name for our instance.

Parameters
name:String

Returns
String
Constant detail
CARDSconstant
protected static const CARDS:String = "trick.cards"
PLAYERSconstant 
protected static const PLAYERS:String = "trick.players"
SIZEconstant 
protected static const SIZE:String = "trick.size"