agi =& $agi; $this->shuffle(); if($this->hand_size) $this->deal(); } function deal() { for($i = 0; $i < $this->hand_size; $i++) if($this->hand[$i] == '') $this->hand[$i] = $this->next_card(); $this->agi->text2wav("Your hand is now: "); for($i = 0; $i < $this->hand_size; $i++) if($this->hand[$i] != '') $this->agi->text2wav($this->card_name($i)); } function shuffle() { // initialize hand for($i = 0; $i < $this->hand_size; $i++) $this->hand[$i] = ''; // create new deck $this->deck = array(); for($i = 0; $i < 13; $i++) for($j = 0; $j < 4; $j++) $this->deck[] = array($i, $j); shuffle($this->deck); } function next_card() { $card = $this->deck[count($this->deck)-1]; unset($this->deck[count($this->deck)-1]); return $card; } function card_name($card) { if(!is_array($card)) $card = $this->hand[$card]; switch($card[0]) { case DECK_JACK: $ret = 'Jack of '; break; case DECK_QUEEN: $ret = 'Queen of '; break; case DECK_KING: $ret = 'King of '; break; case DECK_ACE: $ret = 'Ace of '; break; default: $ret = ($card[0]+2) . ' of '; } switch($card[1]) { case DECK_SPADES: $ret .= 'spades'; break; case DECK_DIAMONDS: $ret .= 'diamonds'; break; case DECK_CLUBS: $ret .= 'clubs'; break; case DECK_HEARTS: $ret .= 'hearts'; break; } return $ret; } } ?>