<!--
    Brian Platz
    CS85 Section 1643
    Professor Geddes
    March 20, 2012
    Assignment: Write a program that deals a random poker hand. 
                Your program does not need to score the hand. 
                It simply needs to deal out a hand of five random cards. 
                Use an array to handle the deck.
    --> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
   <head>
      <title>Deal a Poker Hand</title>
      <style type="text/css">
         body {background-color:#90EE90;
             text-align:center;}
         h1 {color:black; font-family:Ariel; font-size:14pt; font-weight:bold; text-align:center;}
         h2 {color:red; font-family:Ariel; font-size:14pt; font-weight:bold}
         h3 {color:black; font-family:Ariel; font-size:24pt; font-weight:normal}
         table.center {
            margin-left:auto; 
            margin-right:auto;
              }
      </style>    
   </head>
   <body> 
         <?php
           $rank 
= array('2''3''4''5''6''7''8''9''t''j''q''k''a'); // array of card ranks
             
$suit = array('c''d''h''s');                                                 // array of suits
             
$deck = array(52);                                                                // will hold 52 cards
             
$hand = array(5);                                                                // will hold the 5 cards of the hand
            
           
createDeck();    // creates the deck
           
dealCards();    // deals the 5 cards from the deck to the hand
           
printHand();    // prints the hand
       
         
function createDeck() {
           global 
$deck;
           global 
$rank;
           global 
$suit;
           
             
$this_card 0;    // index for cards in $deck; initialize to 0
        
            
for ($this_suit0$this_suit count($suit); $this_suit++) {        // for each suit...
              
for ($this_rank=0$this_rank count($rank); $this_rank++) {    // and for each rank...
                     
$deck[$this_card] = $rank[$this_rank].$suit[$this_suit];    // create a card of that suit/rank
                     
$this_card++;                                                // next card...
                     
}
                 }
             }
             
         function 
dealCards() {
           global 
$deck;
           global 
$hand;
           
             for (
$i 0$i 5$i++) {
                 
$index rand(0count($deck) - 1);
                 
$hand[$i] = $deck[$index];     // take a random card from the deck
                 
array_splice($deck$index1);    // remove the card that was just dealt
                 //unset($deck[$index]);        // eliiminate that card from the deck (NO! this only deletes value, not the index/position)
               

           }
         
         function 
printHand() {
             global 
$hand;
             
           print <<<HERE
           <form action='' method='post' ><h1>Here is your Poker Hand...</h1>
           <table class='center'><tr>
HERE;
        foreach (
$hand as $card) {        // print out each card in the hand
            
echo "<td><img src = 'http://ciswebs.smc.edu/cs85/geddes_james/labs/lab04/cards/".$card.".gif' /></td>";
            }
        echo 
"</tr></table>";
        echo 
"<button type='submit' value='Submit'>Deal Again</button><br/>";
        echo 
"<a href='../index.html#unit4' >Return to Index</a></form>";
        } 
        
      
?>
   </body>
</html>