Closed Thread Icon

Topic awaiting preservation: PHP Card Game... (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=26733" title="Pages that link to Topic awaiting preservation: PHP Card Game... (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: PHP Card Game... <span class="small">(Page 1 of 1)</span>\

 
Ensellitis
Bipolar (III) Inmate

From: Kansas City, MO , USA
Insane since: Feb 2002

posted posted 09-28-2005 08:38

I am working on an online card game. Problem is that it is only suppose to be a 1 deck game, I thought I had it figured out, but guess I don't...

Here is how I am defining the cards...

code:
$usedcards = array();

$cards = array(
"blackjack/cards/h2.gif" , "blackjack/cards/h3.gif" , "blackjack/cards/h4.gif" , "blackjack/cards/h5.gif" , "blackjack/cards/h6.gif" , "blackjack/cards/h7.gif" , "blackjack/cards/h8.gif" , "blackjack/cards/h9.gif" , "blackjack/cards/h10.gif" , "blackjack/cards/h11.gif" , "blackjack/cards/h12.gif" , "blackjack/cards/h13.gif" , "blackjack/cards/h14.gif" , 
"blackjack/cards/s2.gif" , "blackjack/cards/s3.gif" , "blackjack/cards/s4.gif" , "blackjack/cards/s5.gif" , "blackjack/cards/s6.gif" , "blackjack/cards/s7.gif" , "blackjack/cards/s8.gif" , "blackjack/cards/s9.gif" , "blackjack/cards/s10.gif" , "blackjack/cards/s11.gif" , "blackjack/cards/s12.gif" , "blackjack/cards/s13.gif" , "blackjack/cards/s14.gif" , 
"blackjack/cards/d2.gif" , "blackjack/cards/d3.gif" , "blackjack/cards/d4.gif" , "blackjack/cards/d5.gif" , "blackjack/cards/d6.gif" , "blackjack/cards/d7.gif" , "blackjack/cards/d8.gif" , "blackjack/cards/d9.gif" , "blackjack/cards/d10.gif" , "blackjack/cards/d11.gif" , "blackjack/cards/d12.gif" , "blackjack/cards/d13.gif" , "blackjack/cards/d14.gif" , 
"blackjack/cards/c2.gif" , "blackjack/cards/c3.gif" , "blackjack/cards/c4.gif" , "blackjack/cards/c5.gif" , "blackjack/cards/c6.gif" , "blackjack/cards/c7.gif" , "blackjack/cards/c8.gif" , "blackjack/cards/c9.gif" , "blackjack/cards/c10.gif" , "blackjack/cards/c11.gif" , "blackjack/cards/c12.gif" , "blackjack/cards/c13.gif" , "blackjack/cards/c14.gif" ,
"blackjack/cards/joker.gif");

$values = array(
"2" , "3" , "4" , "5" , "6" , "7" , "8" , "9" , "10" , "10" , "10" , "10" , "11" , 
"2" , "3" , "4" , "5" , "6" , "7" , "8" , "9" , "10" , "10" , "10" , "10" , "11" , 
"2" , "3" , "4" , "5" , "6" , "7" , "8" , "9" , "10" , "10" , "10" , "10" , "11" , 
"2" , "3" , "4" , "5" , "6" , "7" , "8" , "9" , "10" , "10" , "10" , "10" , "11" ,
 "11" );

$aces = array(12,25,38,51,52);



Here is a snip of the users hand...

code:
session_unregister("usercard");
	$usercard = array();
	$total = "";
	for ($i = 0; $i < 2; $i++) {
		$num = rand(1000,9999);
		mt_srand ((double) microtime() * 9999999);
		$card = mt_rand (0,52);
		do {
			mt_srand ((double) microtime() * 9999999);
			$card = mt_rand (0,52);
		} while (in_array($card,$usedcards));
		array_push($usedcards,$card);
		$usercard[$i] = $card;
	}
	$total = getTotal($usercard);
	session_register("usercard");

	print showCards($dealercard,"dealershand","<strong>Dealers Hand :</strong>  Don't you wish...");
	print showCards($usercard,"yourhand","<strong>Your Hand</strong> : $total");
	print showChoices();
	print showScore();

}



Seemed to be working for a bit, but all of the sudden I got a hand with a pair of 2 of clubs, and a pair of 2 of diamonds, and the dealer had 2 ace of spades.

Anyone have an idea why this isn't working??

If you need more code, let me know.



(Edited by Ensellitis on 09-28-2005 08:41)

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 09-28-2005 11:30

a) You'r not keeping the image and the card value together... that's prone to cause a bit of trouble when you're shuffling.
Try having an array of array($file,$value);

b) doing a good array shuffle yourself is not that easy. There's a whole section in The Art of Computer Programing on this, I believe.

Why don't you use php->shuffle() instead?

so long,

->Tyberius Prime

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 09-28-2005 18:08

I'd make one array of small "card" data objects. (PHP 5 syntax)

class Card {
public Suit;
public Card;
public Image;
function __construct(img, suit, card) {
$this->Suit = suit;
$this->Card = card;
$this->Image = img;
}
}

2 embedded for loops can construct it for you then you just need to do:

$array[num] = new Card(img,suit,card);

For every new game I'd copy that array to a new one, use shuffle and then array_pop to pull them off of the end.



.:[ Never resist a perfect moment ]:.

« BackwardsOnwards »

Show Forum Drop Down Menu