Cannot Be Bothered To zip It Up So...
create a index.php
create Deck.class.php
create stylesheet_tan.css
create a index.php
Code:
<? include "Deck.class.php"; session_start(); $hideDealer = "hide"; if($bank < 0) { session_register("bank"); $bank=10; } if($playerHand == "") { session_register("deck"); if($wins == "") { session_register("wins"); $wins=0; } session_register("playerHand"); session_register("dealerHand"); session_register("currentBet"); $currentBet="10"; $deck = new Deck(); $playerHand=""; $dealerHand=""; } if($action == 'changeBet') { $currentBet = $bet; } if($action == 'draw') { $playerHand= $playerHand . $deck->drawCard() . ","; if($deck->points($playerHand) > 21) { $message = 'Player Busts'; $bank-=$currentBet; } if($dealerHand=="") { $dealerHand = $dealerHand . $deck->drawCard() . ","; $dealerHand = $dealerHand . $deck->drawCard() . ","; } } if($action == 'new') { $playerHand =""; $dealerHand =""; $hideDealer = "hide"; $playerHand= $playerHand . $deck->drawCard() . ","; $playerHand= $playerHand . $deck->drawCard() . ","; if($deck->points($playerHand) == 21) { $message = 'Player has BlackJack'; $bank+=($currentBet + $currentBet/3); } $dealerHand = $dealerHand . $deck->drawCard() . ","; $dealerHand = $dealerHand . $deck->drawCard() . ","; if($deck->points($dealerHand) == 21) { $message = 'Dealer has BlackJack'; $bank-=$currentBet; } } if($action == 'stay' && $deck->points($playerHand) > 0) { while($deck->points($dealerHand) < 16) { $dealerHand= $dealerHand . $deck->drawCard() . ","; } if($deck->points($dealerHand) > 21) { $message = 'Dealer Busts'; $bank += $currentBet; } else { $action = 'determineWinner'; } } if($action == 'determineWinner') { $dealer = $deck->points($dealerHand); $player = $deck->points($playerHand); if($dealer == 21) { $message = 'Dealer has BlackJack'; $bank-=$currentBet; } elseif($player == 21) { $message = 'Player has BlackJack'; $bank+=($currentBet + ($currentBet/3)); } elseif($player > $dealer) { $message = 'Player wins'; $bank +=$currentBet; } else { $message = 'Push'; } $action ='stay'; } if($action == 'clear') { $playerHand= ""; $dealerHand=""; $message = "Your hand " . $playerHand; } if($action == 'stay' || $deck->points($playerHand) > 21 || $deck->points($dealerHand) > 21 || $deck->points($dealerHand) == 21 || $playerHand == "") { $hideDealer=""; } ?> <html> <head> <title>BlaqJack (PHP Style)</title> <? include "stylesheet_tan.css"; ?> </head> <body> <table border=0 cellpadding=0 cellspacing=0><tr><td> <font class=label> <table border=0 cellpadding=0 cellspacing=0> <tr><td> <font class=norm>Dealer: <? $deck->displayHand($dealerHand, "$hideDealer"); ?> </font> </td></tr> <tr><td> <font class=norm>Player: <? echo $deck->points($playerHand); ?> <? $deck->displayHand($playerHand, ''); ?> </font> </td></tr> </table> <? if ($message) print "<center><font class=norm>[b]" .$message . " [/b]</font></center>"; ?> [url="<?"]?action=draw>Hit[/url] | [url="<?"]?action=stay>Stay[/url] <? if($action == 'stay' || $deck->points($playerHand) > 21 || $deck->points($dealerHand) > 21 || $playerHand == "") { $dealerHand=""; $playerHand=""; ?> [url="<?"]?action=new>New Hand[/url] <? } ?> <form> <input type=hidden name=action value=changeBet> <font class=norm> Bank: <? echo $bank; ?> Bet <input type=text size=4 name=bet value=<? echo $currentBet; ?>><input type=submit value='New Bet'><font class=norm> </font> </tr></td></table> </body> </html>
Code:
<? class Deck { var $worth; var $name; var $suite; var $drawn; function Deck() { $this->shuffle(); } function drawCard() { $card = rand(0, sizeOf($this->name)-1); //print "drawing Card:" . $this->drawn[$card] . " "; while($this->drawn[$card] == 'drawn') { $count++; $card = rand(0, sizeOf($this->name)-1); if($count > 25) { print "took 25th card "; $this->drawn[$card] = 'drawn'; return ($this->name[$card] . " " . $this->suite[$card]); $this->shuffle(); $count=0; } } $this->drawn[$card] = 'drawn'; return ($this->name[$card] . " " . $this->suite[$card]); } function displayHand($hand, $hide) { //print "$hand "; $card = explode(",", $hand); print " <table border=1 height=150 cellpadding=0 cellspacgin=10> <tr>"; $i=0; while($card[$i] ) { $info = explode(" ", $card[$i]); switch($info[0]) { case 'A': $face = 'Ace';break; case 'K': $face = 'King';break; case 'Q': $face = 'Queen';break; case 'J': $face = 'Jack';break; default: $face = $info[0]; } switch($info[1]) { case 'H': $su = 'Hearts';break; case 'S': $su = 'Spades';break; case 'C': $su = 'Clubs';break; case 'D': $su = 'Diamonds';break; default: $su = $info[0]; } if($hide && $i==0) { print"<td width=100 valign=center align=center><font class=norm> Face Down </font></td> "; } else { print"<td width=100 valign=center align=center><font class=norm> " . $face . " of " . $su . " </font></td> "; } $i++; } print "</tr></table>"; } function points($hand) { $total=0; $card = explode(",", $hand); $i=0; while($card[$i] ) { $info = explode(" ", $card[$i]); switch($info[0]) { case 'A': $total += 11;break; case 'K': $total += 10;break; case 'Q': $total += 10;break; case 'J': $total += 10;break; default: $total += $info[0]; } $i++; } return $total; } function getValue($card) { $info = explode(" " ,$card); if($info[0] == 'J') return 10; if($info[0] == 'K') return 10; if($info[0] == 'A') return 10; if($info[0] == 'Q') return 10; return $info[0]; } function shuffle() { //print "Deck Shuffled"; $count=0; for($i=2;$i<11;$i++) { $worth[$count] = $i; $name[$count]=$i; $drawn[$count]=false; $suite[$count]='C'; $count++; } $worth[$count] = 10; $name[$count] = 'J'; $drawn[$count] = false; $suite[$count] = 'C'; $count++; $worth[$count] = 10; $name[$count] = 'Q'; $drawn[$count] = false; $suite[$count] = 'C'; $count++; $worth[$count] = 10; $name[$count] = 'K'; $drawn[$count] = false; $suite[$count] = 'C'; $count++; $worth[$count] = 11; $name[$count] = 'A'; $drawn[$count] = false; $suite[$count] = 'C'; $count++; for($i=2;$i<11;$i++) { $worth[$count] = $i; $name[$count]=$i; $drawn[$count]=false; $suite[$count]='H'; $count++; } $worth[$count] = 10; $name[$count] = 'J'; $drawn[$count] = false; $suite[$count] = 'H'; $count++; $worth[$count] = 10; $name[$count] = 'Q'; $drawn[$count] = false; $suite[$count] = 'H'; $count++; $worth[$count] = 10; $name[$count] = 'K'; $drawn[$count] = false; $suite[$count] = 'H'; $count++; $worth[$count] = 11; $name[$count] = 'A'; $drawn[$count] = false; $suite[$count] = 'H'; $count++; for($i=2;$i<11;$i++) { $worth[$count] = $i; $name[$count]=$i; $drawn[$count]=false; $suite[$count]='S'; $count++; } $worth[$count] = 10; $name[$count] = 'J'; $drawn[$count] = false; $suite[$count] = 'S'; $count++; $worth[$count] = 10; $name[$count] = 'Q'; $drawn[$count] = false; $suite[$count] = 'H'; $count++; $worth[$count] = 10; $name[$count] = 'K'; $drawn[$count] = false; $suite[$count] = 'S'; $count++; $worth[$count] = 11; $name[$count] = 'A'; $drawn[$count] = false; $suite[$count] = 'S'; $count++; for($i=2;$i<11;$i++) { $worth[$count] = $i; $name[$count]=$i; $drawn[$count]=false; $suite[$count]='D'; $count++; } $worth[$count] = 10; $name[$count] = 'J'; $drawn[$count] = false; $suite[$count] = 'D'; $count++; $worth[$count] = 10; $name[$count] = 'Q'; $drawn[$count] = false; $suite[$count] = 'D'; $count++; $worth[$count] = 10; $name[$count] = 'K'; $drawn[$count] = false; $suite[$count] = 'D'; $count++; $worth[$count] = 11; $name[$count] = 'A'; $drawn[$count] = false; $suite[$count] = 'D'; $count++; $this->worth = $worth; $this->name = $name; $this->drawn = $drawn; $this->suite = $suite; } }
Code:
<style> <!-- a:link {font-family: Verdana; font-size: 8Pt; color: #656953; text-decoration: bold; font-weight: bold; } a:visited {font-family: Verdana; font-size: 8Pt; color: #656953; text-decoration: bold; font-weight: bold; } a:hover {font-family: Verdana; font-size: 8Pt; color: #A7B274; text-decoration: underline; font-weight: bold; } font.norm {font-family: Verdana; font-size: 8Pt; color: #656953; font-weight: none;} font.speech {font-family: Verdana; font-size: 8Pt; color: #656953; font-weight: none;} font.label {font-family: Verdana; font-size: 8Pt; color: #FFFFFF; font-weight: bold;} font.header {font-family: Verdana; font-size: 8Pt; color: #000000; font-weight: bold;} font.warnings {font-family: Verdana; font-size: 8Pt; color: #cc0000; font-weight: bold;} td.header {font-family: Verdana; font-size: 8Pt; color: #A50400; align=center; background-color: #A7B274;} td.desc {font-family: Verdana; font-size: 8Pt; color: #000099; align: right; background-color: #656953;} td.data {font-family: Verdana; font-size: 8Pt; color: 000000; align: right; background-color: #000000;} table.borderedTable {{font-family: Verdana; font-size: 8Pt; color: 000000; align: right; border: 1px solid; border-color: #656953;} .button {font-family: Verdana; font-size: 8Pt; font-weight: none; color: #E7E7E7; background-color: #0099cc; border: 1px solid #000099;} .textinput {font-family: Verdana; font-size: 8Pt; color: #656953; background-color: #A7B274; border: 1px solid #000000;} --> </style>
Comment