Jump to content
MakeWebGames

Can anyone help me figure out how to get my blackjack working?


Harley

Recommended Posts

I have struggled with this and even looked at a working game on my website to see if I could get this to work and have had no luck.

Here is the code. Would someone please take a peak and see if anything jumps out? I am a total newb to this.

<?php

include "globals.php";

print "<center><font size='4' face='Arial, Helvetica, sans-serif'>Blackjack</font><hr width=80%>";

if($ir['jailtime'] or $ir['hospital']) { die("

This page is unavailable while in Hospital or Jail.

<hr width=80%>> Home<hr width=80%>");

}

if($ir['money'] <= 0)

{

print'You dont have any Money!!!!!!!';

}

if($currentBet > $ir['money'])

{

die("You are trying to bet more than you have.

> Back");

}

if($currentBet > $maxbet)

{

die("You are trying to bet more than your Max Bet for your level.

> Back");

}

$player = $ir['$userid'];

$hideDealer = "hide";

 

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';

$l-=$currentBet;

$db->query("update users set money=money-{$currentBet} where userid=$userid",);

}

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';

$w+=($currentBet + $currentBet/3);

$db->query("update users set money=money+{$currentBet} where userid=$userid",);

}

$dealerHand = $dealerHand . $deck->drawCard() . ",";

$dealerHand = $dealerHand . $deck->drawCard() . ",";

if($deck->points($dealerHand) == 21)

{

$message = 'Dealer has BlackJack';

$l-=$currentBet;

$db->query("update users set money=money-{$currentBet} where userid=$userid",);

}

 

}

if($action == 'stay' && $deck->points($playerHand) > 0)

{

while($deck->points($dealerHand) < 16)

{

$dealerHand= $dealerHand . $deck->drawCard() . ",";

}

if($deck->points($dealerHand) > 21)

{

$message = 'Dealer Busts';

$w+= $currentBet;

$db->query("update users set money=money+{$currentBet} where userid=$userid",);

}

else

{

$action = 'determineWinner';

}

}

if($action == 'determineWinner')

{

$dealer = $deck->points($dealerHand);

$player = $deck->points($playerHand);

if($dealer == 21)

{

$message = 'Dealer has BlackJack';

$l-=$currentBet;

$db->query("update users set money=money-{$currentBet} where userid=$userid",);

}

elseif($player == 21)

{

$message = 'Player has BlackJack';

$w+=($currentBet + ($currentBet/3));

$db->query("update users set money=money+{$currentBet} where userid=$userid",);

}

elseif($player > $dealer)

{

$message = 'Player wins';

$w+=$currentBet;

$db->query("update users set money=money+{$currentBet} where userid=$userid",);

}

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> BCM Black Jack (PHP Style)</title>

BCM Black Jack

</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>" .$message . "

 

</font></center>";

?>

?action=draw>Hit |

?action=stay>Stay

<?

if($action == 'stay' || $deck->points($playerHand) > 21 || $deck->points($dealerHand) > 21 || $playerHand == "")

{

$dealerHand="";

$playerHand="";

?>

?action=new>New Hand

<?

}

$maxbet=$ir['level']*1000;

?>

<form>

<input type=hidden name=action value=changeBet>

<font class=norm>

Max Bet:<? echo $maxbet; ?> Bet: <input type=text size=10 name=bet value=<? echo $currentBet; ?>><input type=submit value='New Bet'><font class=norm>

</font>

</tr></td></table>

 

</body>

</html>

 

Blackjack<hr width=80%>";

}

$h->endpage();

?>

Link to comment
Share on other sites

Re: Can anyone help me figure out how to get my blackjack working?

use code tags please.

you're using a class "deck" in the file, but don't include the class file anywhere, unless deck is defined in globals.

if it's not in globals, include the file in there see if that helps. otherwise you need to post more information as 1) we don't know what's wrong with it, 2) can't test the class if we don't have the class definition.

Link to comment
Share on other sites

Re: Can anyone help me figure out how to get my blackjack working?

Is this what you need to help me? Sorry but I don't know how to add this to the Globals.

<?

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;

 

}

}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...