Help in card game

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tnrh1
Forum Newbie
Posts: 14
Joined: Tue Nov 30, 2010 8:27 am

Help in card game

Post by tnrh1 »

Hello everyone,
I've wanted to make a cards game but I've been stack in the middle of the project let me show you the code first:

Code: Select all

<?php
echo "<center>Computer: <br>";
for($x=1;$x<14;$x++)
	echo "<img src='images/fold.png' border='1' />";

$cards=array(
"<img src='images/2.png' width='84' height='129' border='1' />",
"<img src='images/3.png' width='84' height='129' border='1' />",
"<img src='images/4.png' width='84' height='129' border='1' />",
"<img src='images/5.png' width='84' height='129' border='1' />",
"<img src='images/6.png' width='84' height='129' border='1' />",
"<img src='images/7.png' width='84' height='129' border='1' />",
"<img src='images/8.png' width='84' height='129' border='1' />",
"<img src='images/9.png' width='84' height='129' border='1' />",
"<img src='images/10.png' width='84' height='129' border='1' />",
"<img src='images/J.png' width='84' height='129' border='1' />",
"<img src='images/Q.png' width='84' height='129' border='1' />",
"<img src='images/K.png' width='84' height='129' border='1' />",
"<img src='images/A.png' width='84' height='129' border='1' />");

echo "<br><br><br><br><br><br>";
$rndflop = array_rand($cards,1);
$flop = $cards[$rndflop];
echo "flop:<br>$flop";
echo "<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>";

$randArr = array_rand($cards,13);
$userC = array();
echo "<center>Your cards are:<br> ";
for($counter=0;$counter<=12;$counter++)
	{
		$userC[$counter] =  $cards[$randArr[$counter]];
		echo $userC[$counter]." ";
	}
?>
you can also see it in here: http://81.218.161.218:8888/cards/
I have few problems

-when the computer for example get 2 king I can get even 3 kings, which means there is no maximum cards of each kind.
-Since the array values are images I cant do any Mathematical calculations.

any suggestions?
Thanks in advanced.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Help in card game

Post by requinix »

tnrh1 wrote:-when the computer for example get 2 king I can get even 3 kings, which means there is no maximum cards of each kind.
Create an array of all the cards in the deck. shuffle() it. Then use array_slice() to pick the first 13 cards for the computer and the second 13 cards for the player.
tnrh1 wrote:-Since the array values are images I cant do any Mathematical calculations.
Then don't use images.
tnrh1
Forum Newbie
Posts: 14
Joined: Tue Nov 30, 2010 8:27 am

Re: Help in card game

Post by tnrh1 »

I cant make a card game with pictures ... -.-
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Help in card game

Post by requinix »

Didn't know you were one to take things literally. :?

Don't use images until the very end. Before that point, deal with (eg) numbers.
Post Reply