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.
protected var _beats:Function
protected var _cards:CardArray
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
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
protected var _gameCtrl:GameControl
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
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
length:int [read-only]
Access the number of cards played so far.
Implementation
public function get length():int
protected var _numPlayers:int
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
protected var _players:Array
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
protected var _prefix:String
protected var _winner:int
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
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 |
protected function calculateWinner():int
Returns
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
protected function handlePropertyChanged(event:PropertyChangedEvent):voidParameters
| event:PropertyChangedEvent |
public function hasPlayed(playerId:int):Boolean Tests whether the player with the id has already put a card into the trick.
Parameters
Returns
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
Throws
| — if the trick is already full |
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.
protected function updateFromServer():void
protected function varName(name:String):String Prefix the name for our instance.
Parameters
Returns
protected static const CARDS:String = "trick.cards"
protected static const PLAYERS:String = "trick.players"
protected static const SIZE:String = "trick.size"