Game Development Reference
In-Depth Information
Getting the initial three cards
In the start method, notice that we make a call to the getCard method. The following
is the listing of the getCard method. This method is called during the start method
as well as after the player plays or discards a card during his or her turn.
private function getCard():void {
if ( m_mgr.getMyHand().length == 3 )
return;
var c:Card;
c = m_mgr.getTopCard();
if ( c == null ) {
trace("No more cards in the deck!!");
m_mgr.traceCount();
}
var req:HandCardClient;
req = new HandCardClient();
req.setCardId(c.id);
req.setStateKey(""+c.id);
m_pulse.addGameState(req);
}
The game always requires there to be three cards in the player's hand. If there are
already three cards, we simply return from the method. If not, we get a card from the
deck and attempt to put it on the player's hand. This attempt may fail, in which case
the card already belongs to another player, or may succeed, in which case we move
the card to player's hand and refresh the display.
The process hand card is listed below:
public function processHandCard(gameState:GameStateClient,
error:Boolean):void {
var gs:HandCardClient;
gs = gameState as HandCardClient;
var cid:int;
cid = gs.getCardId();
// if error then try another card from deck
// ...
// If not error
// If mine, put on screen, move to my hand
// else, move card to others
if ( error ) {
m_mgr.toOthers(cid);
getCard();
}
 
Search WWH ::




Custom Search