rendered paste body<?php
define('DECK_TWO', 0);
define('DECK_THREE', 1);
define('DECK_FOUR', 2);
define('DECK_FIVE', 3);
define('DECK_SIX', 4);
define('DECK_SEVEN', 5);
define('DECK_EIGHT', 6);
define('DECK_NINE', 7);
define('DECK_TEN', 8);
define('DECK_JACK', 9);
define('DECK_QUEEN', 10);
define('DECK_KING', 11);
define('DECK_ACE', 12);
define('DECK_SPADES', 0);
define('DECK_DIAMONDS', 1);
define('DECK_CLUBS', 2);
define('DECK_HEARTS', 3);
class deck
{
var $hand_size = 5;
var $hand = array();
var $deck = array();
function deck(&$agi)
{
$this->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;
}
}
?>