Page 1 of 1

Help in card game

Posted: Tue Nov 30, 2010 8:33 am
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.

Re: Help in card game

Posted: Tue Nov 30, 2010 11:32 am
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.

Re: Help in card game

Posted: Tue Nov 30, 2010 3:39 pm
by tnrh1
I cant make a card game with pictures ... -.-

Re: Help in card game

Posted: Tue Nov 30, 2010 9:15 pm
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.