I made a cards game using PHP and all that's left now is that instead of echo'ing, 10, 3, Queen, King for example it should echo a random suited King when i Draw a King. I don't really know how this should be done.
Currently i have this function to show the hand of the player and the dealer (this one is for the dealer):
function list_dealer_hand() {
foreach($_SESSION["dealer_hand"] as $hand_item) {
echo $hand_item . ', ';
echo '<img src="cardImages/h10.jpeg" border=0> ';
}
}
The first echo will echo out what's in the dealer his hand using text, Like 10, Queen, Ace. For example. And the echo beneath that is an echo that will echo out the h10.jpeg, which in this case is the 10 of hearts. I have all cards from all suits in an folder named cardImages.
Is there a possibility to, for example, if the dealer has a 10 in his hand it would grab a random 10 from the images folder?
The array im currently using for the cards:
if(!isset($_SESSION["dealer_pile"])) $_SESSION["dealer_pile"] = array(
'Jack', 'Queen', 'King', 'Ace', '10', '9', '8', '7', '6', '5', '4', '3', '2'
);
I appreciate any help or push in the right direction! Thanks in advance!
EDIT: Card cases:
// Case for each card, points
function get_card_value($card, $current_total) {
switch($card) {
case "King":
case "Queen":
case "Jack":
case "10":
return 10;
case "Ace":
return ($current_total > 10) ? 1 : 11;
case "9":
case "8":
case "7":
case "6":
case "5":
case "4":
case "3":
case "2":
return (int) $card;
}
return 0;
}
$_SESSION['dealer_pile']the card (a 10) but does not specify the suit (10 of hearts)? You want to randomly choose from the images resulting in a random suit?Echo 'Two';it should echo a random suited Two. I hope this clears things up!