Gå til innhold

[Løst] Trenger noe hjelp med en funksjon i PHP.


Anbefalte innlegg

Heisann,

 

Har scriptet en funksjon kalt PlayingCardDeck(blackjack), men når en bruker starter en blackjack runde så vil ikke kortenes verdi vises av en eller annen grunn, men runden blir startet selfølgelig. Men hvis jeg blir med på blackjack runden til den andre brukeren så vises kortene mine.

 

Her er scriptet som oppretter runden (lager kortene og henter korte(ne)'s verdi)

 

<?php


function getDeckValue($deck, $return_value = true)
{
 foreach ($deck as $key => $card)
 {
  if ($card[1] == 11)
  {
unset($deck[$key]);
$deck[] = $card;
  }
 }

 $current_value = 0;
 foreach ($deck as $card)
 {
  $value = $card[1];
  if ($value == 11)
  {
$value = $current_value+11 > 21 ? 1 : 11;
  }

  $current_value += $value;
 }

 return $return_value === true ? $current_value : $deck;
}

$sql = $db->Query("SELECT * FROM `blackjack` WHERE (`dealer`='".Player::Data('id')."' OR `opponent`='".Player::Data('id')."') AND `active`='1'");
$bjRound = $db->FetchArray($sql);

if ($bjRound['id'] == '')
{
 if (isset($_POST['round_bet']))
 {
  $bet = View::NumbersOnly($db->EscapeString($_POST['round_bet']));

  if ($bet > Player::Data('cash'))
  {
echo View::Message('Du har ikke nok penger.', 2);
  }
  elseif ($bet <= 0)
  {
echo View::Message('Du må satse mer enn 0 kr.', 2);
  }
  else
  {
// opprett kortstokk
$theDeck = new PlayingCardDeck();

// trekk 2 første kort
$totalValue = 0;
$cards = array();

for ($i = 0; $i < 2; $i++)
{
 $card = $theDeck->drawCard();

 // finn kortes verdi
 $value = $card[2];
 if (!is_numeric($value))
 {
  $value = $value != 'ace' ? 10 : ($totalValue + 11 > 21 ? 1 : 11);
 }

 $cards[] = array($card, $value);
 $totalValue += $value;
}

$db->Query("UPDATE `[players]` SET `cash`=`cash`-'".$bet."' WHERE `id`='".Player::Data('id')."'");
$db->Query("INSERT INTO `blackjack` (`dealer`, `dealer_bet`, `dealer_state`, `started`, `dealer_cards`, `opponent_cards`, `cardDeck`, `create_ip`)VALUES('".Player::Data('id')."', '".$bet."', '1', '".time()."', '".serialize($cards)."', '".serialize(array())."', '".$theDeck->getDeck(true)."', '".$_SERVER['REMOTE_ADDR']."')");

View::Message('Du har startet en blackjack-runde.', 1, true);
  }
 }
 elseif (isset($_POST['join_round']))
 {
  $round = $db->EscapeString($_POST['join_round']);
  $sql = $db->Query("SELECT id,dealer_bet,cardDeck,opponent FROM `blackjack` WHERE `id`='".$round."' AND `active`='1' AND `opponent`!='".Player::Data('id')."' AND `dealer`!='".Player::Data('id')."'");
  $round = $db->FetchArray($sql);
  $bet = $round['dealer_bet'];

  if ($round['id'] == '' || $round['opponent'] != 0)
  {
echo View::Message('Ugyldig runde.', 2);
  }
  elseif ($bet > Player::Data('cash'))
  {
echo View::Message('Du har ikke nok penger.', 2);
  }
  else
  {
// oppretter kortstokk
$theDeck = new PlayingCardDeck(unserialize($round['cardDeck']));

// 2 første kort
$totalValue = 0;
$cards = array();

for ($i = 0; $i < 2; $i++)
{
 $card = $theDeck->drawCard();

 // finn kortes verdi
 $value = $card[2];
 if (!is_numeric($value))
 {
  $value = $value != 'ace' ? 10 : ($totalValue + 11 > 21 ? 1 : 11);
 }

 $cards[] = array($card, $value);
 $totalValue += $value;
}

$db->Query("UPDATE `[players]` SET `cash`=`cash`-'".$bet."' WHERE `id`='".Player::Data('id')."'");
$db->Query("UPDATE `blackjack` SET `opponent`='".Player::Data('id')."', `opponent_bet`='".$bet."', `opponent_cards`='".serialize($cards)."', `opponent_state`='1', `cardDeck`='".$theDeck->getDeck(true)."' WHERE `id`='".$round['id']."'");

View::Message('Du har blitt med på en blackjack-runde.', 1, true);
  }
 }
?>

 

Setter pris på all hjelp jeg kan få :)

Endret av KRIZx
Lenke til kommentar
Videoannonse
Annonse

Du bør nok legge inn litt debuggings kode for å se hva som foregår, f.eks.

$theDeck = new PlayingCardDeck(unserialize($round['cardDeck']));
echo '<pre>'.print_r($theDeck,true).'</pre>';

Du har trolig en logisk feil ett sted, og da er det kjekt å dobbelt sjekke at variabler og funksjoner innholder/returnerer ting som forventet.

 

Du har også litt dobbel/gjentakende kode, der hvor kortstokken opprettes og kort trekkes, som kan flyttes til en funksjon.

Lenke til kommentar

Har enda ikke funnet feilen..

For å være helt ærlig slike innlegg gjør at jeg mister litt lysten på å hjelpe. Hva har du testet siden sist? Har du dobbelt sjekket at variablene og objektene er og inneholder verdier som forventet? Hva med å fortelle oss om resultatet av hva du har gjort? Slik at vi får "mer kjøtt på beinet" og det er enklere å se hva som foregår, og hva som eventuelt er galt. Du må hjelpe oss å hjelp deg.

  • Liker 2
Lenke til kommentar

Vanskelig å si uten å se PlayingCardDeck-klassen.

 

PlayingCardDeck-klassen:

<?php
if(! defined('BASEPATH') ){ exit('Unable to view file.'); }


class PlayingCardDeck
{
 private $stockDeck = array(
  /*
   id => id, suit, name, initial
  */

  array(1, 'clubs', 'ace', 'a'),
  array(2, 'clubs', 2, '2'),
  array(3, 'clubs', 3, '3'),
  array(4, 'clubs', 4, '4'),
  array(5, 'clubs', 5, '5'),
  array(6, 'clubs', 6, '6'),
  array(7, 'clubs', 7, '7'),
  array(8, 'clubs', 8, '8'),
  array(9, 'clubs', 9, '9'),
  array(10, 'clubs', 10, '10'),
  array(11, 'clubs', 'jack', 'j'),
  array(12, 'clubs', 'queen', 'q'),
  array(13, 'clubs', 'king', 'k'),

  array(14, 'diamonds', 'ace', 'a'),
  array(15, 'diamonds', 2, '2'),
  array(16, 'diamonds', 3, '3'),
  array(17, 'diamonds', 4, '4'),
  array(18, 'diamonds', 5, '5'),
  array(19, 'diamonds', 6, '6'),
  array(20, 'diamonds', 7, '7'),
  array(21, 'diamonds', 8, '8'),
  array(22, 'diamonds', 9, '9'),
  array(23, 'diamonds', 10, '10'),
  array(24, 'diamonds', 'jack', 'j'),
  array(25, 'diamonds', 'queen', 'q'),
  array(26, 'diamonds', 'king', 'k'),

  array(27, 'hearts', 'ace', 'a'),
  array(28, 'hearts', 2, '2'),
  array(29, 'hearts', 3, '3'),
  array(30, 'hearts', 4, '4'),
  array(31, 'hearts', 5, '5'),
  array(32, 'hearts', 6, '6'),
  array(33, 'hearts', 7, '7'),
  array(34, 'hearts', 8, '8'),
  array(35, 'hearts', 9, '9'),
  array(36, 'hearts', 10, '10'),
  array(37, 'hearts', 'jack', 'j'),
  array(38, 'hearts', 'queen', 'q'),
  array(39, 'hearts', 'king', 'k'),

  array(40, 'spades', 'ace', 'a'),
  array(41, 'spades', 2, '2'),
  array(42, 'spades', 3, '3'),
  array(43, 'spades', 4, '4'),
  array(44, 'spades', 5, '5'),
  array(45, 'spades', 6, '6'),
  array(46, 'spades', 7, '7'),
  array(47, 'spades', 8, '8'),
  array(48, 'spades', 9, '9'),
  array(49, 'spades', 10, '10'),
  array(50, 'spades', 'jack', 'j'),
  array(51, 'spades', 'queen', 'q'),
  array(52, 'spades', 'king', 'k')
 );

 private $theDeck = array();


 function __construct($setDeck = false)
 {
  $this->setDeck(is_array($setDeck) ? $setDeck : $this->stockDeck);
 }

 function setDeck($deck)
 {
  $this->theDeck = $deck;
 }

 function getDeck($serialize = false)
 {
  return $serialize !== false ? serialize($this->theDeck) : $this->theDeck;
 }

 function drawCard()
 {
  $card = array_rand($this->theDeck);
  $theCard = $this->theDeck[$card];

  unset($this->theDeck[$card]);

  return $theCard;
 }
}
?>

Lenke til kommentar

Jeg endret litt på koden slik at jeg kunne teste den uten en database, og ting ser ut til å fungere greit.

 

<?php session_start();

function getDeckValue($deck, $return_value = true) {
foreach ($deck as $key => $card) {
	if ($card[1] == 11) {
		unset($deck[$key]);
		$deck[] = $card;
	}
}
$current_value = 0;
foreach ($deck as $card) {
	$value = $card[1];
	if ($value == 11) {
		$value = $current_value + 11 > 21 ? 1 : 11;
	}
	$current_value += $value;
}
return $return_value === true ? $current_value : $deck;
}
$bjRound['id'] = '';
$pl_data = array('cash'=>500);
if ($bjRound['id'] == '') {
if (isset($_GET['round_bet'])) {
	$bet = (int)$_GET['round_bet'];
	if ($bet > $pl_data['cash']) {
		echo 'Du har ikke nok penger.';
	} elseif ($bet <= 0) {
		echo 'Du må satse mer enn 0 kr.';
	} else {
		// opprett kortstokk
		$theDeck = new PlayingCardDeck();
		// trekk 2 første kort
		$totalValue = 0;
		$cards = array();
		for ($i = 0; $i < 2; $i++) {
			$card = $theDeck->drawCard();
			// finn kortes verdi
			$value = $card[2];
			if (!is_numeric($value)) {
				$value = $value != 'ace' ? 10 : ($totalValue + 11 > 21 ? 1 : 11);
			}
			$cards[] = array($card, $value);
			$totalValue += $value;
		}
		$_SESSION['theDeck'] = $theDeck->getDeck(true);
		//$db->Query("UPDATE `[players]` SET `cash`=`cash`-'" . $bet . "' WHERE `id`='" . $pl_data('id') . "'");
		//$db->Query("INSERT INTO `blackjack` (`dealer`, `dealer_bet`, `dealer_state`, `started`, `dealer_cards`, `opponent_cards`, `cardDeck`, `create_ip`)VALUES('" . $pl_data('id') . "', '" . $bet . "', '1', '" . time() . "', '" . serialize($cards) . "', '" . serialize(array()) . "', '" . $theDeck->getDeck(true) . "', '" . $_SERVER['REMOTE_ADDR'] . "')");
		echo 'Du har startet en blackjack-runde.<br/>';
		echo '<pre>'.
				'Cards :'.PHP_EOL.print_r($cards,true).PHP_EOL.
				'Tot Value: '.$totalValue.PHP_EOL.PHP_EOL.
				'The Deck:'.PHP_EOL.print_r($theDeck->getDeck(),true).
			'</pre>';
	}
} elseif (isset($_GET['join_round'])) {
	//$round = (int)$_GET['join_round'];
	//$sql = "SELECT id,dealer_bet,cardDeck,opponent FROM `blackjack` WHERE `id`='" . $round . "' AND `active`='1' AND `opponent`!='" . $pl_data('id') . "' AND `dealer`!='" . $pl_data('id') . "'";
	//$round = $db->FetchArray($sql);
	$round = array(
		'id'=>1,
		'opponent' => 0,
		'cardDeck' => false,
		'dealer_bet'=>10
	);
	$bet = $round['dealer_bet'];
	if ($round['id'] == '' || $round['opponent'] != 0) {
		echo 'Ugyldig runde.';
	} elseif ($bet > $pl_data['cash']) {
		echo 'Du har ikke nok penger.';
	} else {
		// oppretter kortstokk
		$theDeck = new PlayingCardDeck(isset($_SESSION['theDeck']) ? unserialize($_SESSION['theDeck']) : false);
		// 2 første kort
		$totalValue = 0;
		$cards = array();
		for ($i = 0; $i < 2; $i++) {
			$card = $theDeck->drawCard();
			// finn kortes verdi
			$value = $card[2];
			if (!is_numeric($value)) {
				$value = $value != 'ace' ? 10 : ($totalValue + 11 > 21 ? 1 : 11);
			}
			$cards[] = array($card, $value);
			$totalValue += $value;
		}
		//$db->Query("UPDATE `[players]` SET `cash`=`cash`-'" . $bet . "' WHERE `id`='" . $pl_data('id') . "'");
		//$db->Query("UPDATE `blackjack` SET `opponent`='" . $pl_data('id') . "', `opponent_bet`='" . $bet . "', `opponent_cards`='" . serialize($cards) . "', `opponent_state`='1', `cardDeck`='" . $theDeck->getDeck(true) . "' WHERE `id`='" . $round['id'] . "'");
		echo 'Du har blitt med på en blackjack-runde.<br/>';
		echo '<pre>'.
				'Cards :'.PHP_EOL.print_r($cards,true).PHP_EOL.
				'Tot Value: '.$totalValue.PHP_EOL.PHP_EOL.
				'The Deck:'.PHP_EOL.print_r($theDeck->getDeck(),true).
			'</pre>';
	}
}
}

 

 

Debuggingen i bunn gir dette resultatet når jeg starter en runde, det trekkes to kort, de summeres riktig, og getDeck() returnerer en kortstokk.

 


Du har startet en blackjack-runde.
Cards :
Array
(
[0] => Array
	(
		[0] => Array
			(
				[0] => 49
				[1] => spades
				[2] => 10
				[3] => 10
			)
		[1] => 10
	)
[1] => Array
	(
		[0] => Array
			(
				[0] => 8
				[1] => clubs
				[2] => 8
				[3] => 8
			)
		[1] => 8
	)
)

Tot Value: 18

The Deck:
Array
(
[0] => Array
	(
		[0] => 1
		[1] => clubs
		[2] => ace
		[3] => a
	)
[1] => Array
	(
		[0] => 2
		[1] => clubs
		[2] => 2
		[3] => 2
	)
[2] => Array
	(
		[0] => 3
		[1] => clubs
		[2] => 3
		[3] => 3
	)
[3] => Array
	(
		[0] => 4
		[1] => clubs
		[2] => 4
		[3] => 4
	)
[4] => Array
	(
		[0] => 5
		[1] => clubs
		[2] => 5
		[3] => 5
	)
[5] => Array
	(
		[0] => 6
		[1] => clubs
		[2] => 6
		[3] => 6
	)
[6] => Array
	(
		[0] => 7
		[1] => clubs
		[2] => 7
		[3] => 7
	)
[8] => Array
	(
		[0] => 9
		[1] => clubs
		[2] => 9
		[3] => 9
	)
[9] => Array
	(
		[0] => 10
		[1] => clubs
		[2] => 10
		[3] => 10
	)
[10] => Array
	(
		[0] => 11
		[1] => clubs
		[2] => jack
		[3] => j
	)
[11] => Array
	(
		[0] => 12
		[1] => clubs
		[2] => queen
		[3] => q
	)
[12] => Array
	(
		[0] => 13
		[1] => clubs
		[2] => king
		[3] => k
	)
[13] => Array
	(
		[0] => 14
		[1] => diamonds
		[2] => ace
		[3] => a
	)
[14] => Array
	(
		[0] => 15
		[1] => diamonds
		[2] => 2
		[3] => 2
	)
[15] => Array
	(
		[0] => 16
		[1] => diamonds
		[2] => 3
		[3] => 3
	)
[16] => Array
	(
		[0] => 17
		[1] => diamonds
		[2] => 4
		[3] => 4
	)
[17] => Array
	(
		[0] => 18
		[1] => diamonds
		[2] => 5
		[3] => 5
	)
[18] => Array
	(
		[0] => 19
		[1] => diamonds
		[2] => 6
		[3] => 6
	)
[19] => Array
	(
		[0] => 20
		[1] => diamonds
		[2] => 7
		[3] => 7
	)
[20] => Array
	(
		[0] => 21
		[1] => diamonds
		[2] => 8
		[3] => 8
	)
[21] => Array
	(
		[0] => 22
		[1] => diamonds
		[2] => 9
		[3] => 9
	)
[22] => Array
	(
		[0] => 23
		[1] => diamonds
		[2] => 10
		[3] => 10
	)
[23] => Array
	(
		[0] => 24
		[1] => diamonds
		[2] => jack
		[3] => j
	)
[24] => Array
	(
		[0] => 25
		[1] => diamonds
		[2] => queen
		[3] => q
	)
[25] => Array
	(
		[0] => 26
		[1] => diamonds
		[2] => king
		[3] => k
	)
[26] => Array
	(
		[0] => 27
		[1] => hearts
		[2] => ace
		[3] => a
	)
[27] => Array
	(
		[0] => 28
		[1] => hearts
		[2] => 2
		[3] => 2
	)
[28] => Array
	(
		[0] => 29
		[1] => hearts
		[2] => 3
		[3] => 3
	)
[29] => Array
	(
		[0] => 30
		[1] => hearts
		[2] => 4
		[3] => 4
	)
[30] => Array
	(
		[0] => 31
		[1] => hearts
		[2] => 5
		[3] => 5
	)
[31] => Array
	(
		[0] => 32
		[1] => hearts
		[2] => 6
		[3] => 6
	)
[32] => Array
	(
		[0] => 33
		[1] => hearts
		[2] => 7
		[3] => 7
	)
[33] => Array
	(
		[0] => 34
		[1] => hearts
		[2] => 8
		[3] => 8
	)
[34] => Array
	(
		[0] => 35
		[1] => hearts
		[2] => 9
		[3] => 9
	)
[35] => Array
	(
		[0] => 36
		[1] => hearts
		[2] => 10
		[3] => 10
	)
[36] => Array
	(
		[0] => 37
		[1] => hearts
		[2] => jack
		[3] => j
	)
[37] => Array
	(
		[0] => 38
		[1] => hearts
		[2] => queen
		[3] => q
	)
[38] => Array
	(
		[0] => 39
		[1] => hearts
		[2] => king
		[3] => k
	)
[39] => Array
	(
		[0] => 40
		[1] => spades
		[2] => ace
		[3] => a
	)
[40] => Array
	(
		[0] => 41
		[1] => spades
		[2] => 2
		[3] => 2
	)
[41] => Array
	(
		[0] => 42
		[1] => spades
		[2] => 3
		[3] => 3
	)
[42] => Array
	(
		[0] => 43
		[1] => spades
		[2] => 4
		[3] => 4
	)
[43] => Array
	(
		[0] => 44
		[1] => spades
		[2] => 5
		[3] => 5
	)
[44] => Array
	(
		[0] => 45
		[1] => spades
		[2] => 6
		[3] => 6
	)
[45] => Array
	(
		[0] => 46
		[1] => spades
		[2] => 7
		[3] => 7
	)
[46] => Array
	(
		[0] => 47
		[1] => spades
		[2] => 8
		[3] => 8
	)
[47] => Array
	(
		[0] => 48
		[1] => spades
		[2] => 9
		[3] => 9
	)
[49] => Array
	(
		[0] => 50
		[1] => spades
		[2] => jack
		[3] => j
	)
[50] => Array
	(
		[0] => 51
		[1] => spades
		[2] => queen
		[3] => q
	)
[51] => Array
	(
		[0] => 52
		[1] => spades
		[2] => king
		[3] => k
	)
)

 

Lenke til kommentar

Jeg endret litt på koden slik at jeg kunne teste den uten en database, og ting ser ut til å fungere greit.

 

<?php session_start();

function getDeckValue($deck, $return_value = true) {
foreach ($deck as $key => $card) {
	if ($card[1] == 11) {
		unset($deck[$key]);
		$deck[] = $card;
	}
}
$current_value = 0;
foreach ($deck as $card) {
	$value = $card[1];
	if ($value == 11) {
		$value = $current_value + 11 > 21 ? 1 : 11;
	}
	$current_value += $value;
}
return $return_value === true ? $current_value : $deck;
}
$bjRound['id'] = '';
$pl_data = array('cash'=>500);
if ($bjRound['id'] == '') {
if (isset($_GET['round_bet'])) {
	$bet = (int)$_GET['round_bet'];
	if ($bet > $pl_data['cash']) {
		echo 'Du har ikke nok penger.';
	} elseif ($bet <= 0) {
		echo 'Du må satse mer enn 0 kr.';
	} else {
		// opprett kortstokk
		$theDeck = new PlayingCardDeck();
		// trekk 2 første kort
		$totalValue = 0;
		$cards = array();
		for ($i = 0; $i < 2; $i++) {
			$card = $theDeck->drawCard();
			// finn kortes verdi
			$value = $card[2];
			if (!is_numeric($value)) {
				$value = $value != 'ace' ? 10 : ($totalValue + 11 > 21 ? 1 : 11);
			}
			$cards[] = array($card, $value);
			$totalValue += $value;
		}
		$_SESSION['theDeck'] = $theDeck->getDeck(true);
		//$db->Query("UPDATE `[players]` SET `cash`=`cash`-'" . $bet . "' WHERE `id`='" . $pl_data('id') . "'");
		//$db->Query("INSERT INTO `blackjack` (`dealer`, `dealer_bet`, `dealer_state`, `started`, `dealer_cards`, `opponent_cards`, `cardDeck`, `create_ip`)VALUES('" . $pl_data('id') . "', '" . $bet . "', '1', '" . time() . "', '" . serialize($cards) . "', '" . serialize(array()) . "', '" . $theDeck->getDeck(true) . "', '" . $_SERVER['REMOTE_ADDR'] . "')");
		echo 'Du har startet en blackjack-runde.<br/>';
		echo '<pre>'.
				'Cards :'.PHP_EOL.print_r($cards,true).PHP_EOL.
				'Tot Value: '.$totalValue.PHP_EOL.PHP_EOL.
				'The Deck:'.PHP_EOL.print_r($theDeck->getDeck(),true).
			'</pre>';
	}
} elseif (isset($_GET['join_round'])) {
	//$round = (int)$_GET['join_round'];
	//$sql = "SELECT id,dealer_bet,cardDeck,opponent FROM `blackjack` WHERE `id`='" . $round . "' AND `active`='1' AND `opponent`!='" . $pl_data('id') . "' AND `dealer`!='" . $pl_data('id') . "'";
	//$round = $db->FetchArray($sql);
	$round = array(
		'id'=>1,
		'opponent' => 0,
		'cardDeck' => false,
		'dealer_bet'=>10
	);
	$bet = $round['dealer_bet'];
	if ($round['id'] == '' || $round['opponent'] != 0) {
		echo 'Ugyldig runde.';
	} elseif ($bet > $pl_data['cash']) {
		echo 'Du har ikke nok penger.';
	} else {
		// oppretter kortstokk
		$theDeck = new PlayingCardDeck(isset($_SESSION['theDeck']) ? unserialize($_SESSION['theDeck']) : false);
		// 2 første kort
		$totalValue = 0;
		$cards = array();
		for ($i = 0; $i < 2; $i++) {
			$card = $theDeck->drawCard();
			// finn kortes verdi
			$value = $card[2];
			if (!is_numeric($value)) {
				$value = $value != 'ace' ? 10 : ($totalValue + 11 > 21 ? 1 : 11);
			}
			$cards[] = array($card, $value);
			$totalValue += $value;
		}
		//$db->Query("UPDATE `[players]` SET `cash`=`cash`-'" . $bet . "' WHERE `id`='" . $pl_data('id') . "'");
		//$db->Query("UPDATE `blackjack` SET `opponent`='" . $pl_data('id') . "', `opponent_bet`='" . $bet . "', `opponent_cards`='" . serialize($cards) . "', `opponent_state`='1', `cardDeck`='" . $theDeck->getDeck(true) . "' WHERE `id`='" . $round['id'] . "'");
		echo 'Du har blitt med på en blackjack-runde.<br/>';
		echo '<pre>'.
				'Cards :'.PHP_EOL.print_r($cards,true).PHP_EOL.
				'Tot Value: '.$totalValue.PHP_EOL.PHP_EOL.
				'The Deck:'.PHP_EOL.print_r($theDeck->getDeck(),true).
			'</pre>';
	}
}
}

 

 

Debuggingen i bunn gir dette resultatet når jeg starter en runde, det trekkes to kort, de summeres riktig, og getDeck() returnerer en kortstokk.

 


Du har startet en blackjack-runde.
Cards :
Array
(
[0] => Array
	(
		[0] => Array
			(
				[0] => 49
				[1] => spades
				[2] => 10
				[3] => 10
			)
		[1] => 10
	)
[1] => Array
	(
		[0] => Array
			(
				[0] => 8
				[1] => clubs
				[2] => 8
				[3] => 8
			)
		[1] => 8
	)
)

Tot Value: 18

The Deck:
Array
(
[0] => Array
	(
		[0] => 1
		[1] => clubs
		[2] => ace
		[3] => a
	)
[1] => Array
	(
		[0] => 2
		[1] => clubs
		[2] => 2
		[3] => 2
	)
[2] => Array
	(
		[0] => 3
		[1] => clubs
		[2] => 3
		[3] => 3
	)
[3] => Array
	(
		[0] => 4
		[1] => clubs
		[2] => 4
		[3] => 4
	)
[4] => Array
	(
		[0] => 5
		[1] => clubs
		[2] => 5
		[3] => 5
	)
[5] => Array
	(
		[0] => 6
		[1] => clubs
		[2] => 6
		[3] => 6
	)
[6] => Array
	(
		[0] => 7
		[1] => clubs
		[2] => 7
		[3] => 7
	)
[8] => Array
	(
		[0] => 9
		[1] => clubs
		[2] => 9
		[3] => 9
	)
[9] => Array
	(
		[0] => 10
		[1] => clubs
		[2] => 10
		[3] => 10
	)
[10] => Array
	(
		[0] => 11
		[1] => clubs
		[2] => jack
		[3] => j
	)
[11] => Array
	(
		[0] => 12
		[1] => clubs
		[2] => queen
		[3] => q
	)
[12] => Array
	(
		[0] => 13
		[1] => clubs
		[2] => king
		[3] => k
	)
[13] => Array
	(
		[0] => 14
		[1] => diamonds
		[2] => ace
		[3] => a
	)
[14] => Array
	(
		[0] => 15
		[1] => diamonds
		[2] => 2
		[3] => 2
	)
[15] => Array
	(
		[0] => 16
		[1] => diamonds
		[2] => 3
		[3] => 3
	)
[16] => Array
	(
		[0] => 17
		[1] => diamonds
		[2] => 4
		[3] => 4
	)
[17] => Array
	(
		[0] => 18
		[1] => diamonds
		[2] => 5
		[3] => 5
	)
[18] => Array
	(
		[0] => 19
		[1] => diamonds
		[2] => 6
		[3] => 6
	)
[19] => Array
	(
		[0] => 20
		[1] => diamonds
		[2] => 7
		[3] => 7
	)
[20] => Array
	(
		[0] => 21
		[1] => diamonds
		[2] => 8
		[3] => 8
	)
[21] => Array
	(
		[0] => 22
		[1] => diamonds
		[2] => 9
		[3] => 9
	)
[22] => Array
	(
		[0] => 23
		[1] => diamonds
		[2] => 10
		[3] => 10
	)
[23] => Array
	(
		[0] => 24
		[1] => diamonds
		[2] => jack
		[3] => j
	)
[24] => Array
	(
		[0] => 25
		[1] => diamonds
		[2] => queen
		[3] => q
	)
[25] => Array
	(
		[0] => 26
		[1] => diamonds
		[2] => king
		[3] => k
	)
[26] => Array
	(
		[0] => 27
		[1] => hearts
		[2] => ace
		[3] => a
	)
[27] => Array
	(
		[0] => 28
		[1] => hearts
		[2] => 2
		[3] => 2
	)
[28] => Array
	(
		[0] => 29
		[1] => hearts
		[2] => 3
		[3] => 3
	)
[29] => Array
	(
		[0] => 30
		[1] => hearts
		[2] => 4
		[3] => 4
	)
[30] => Array
	(
		[0] => 31
		[1] => hearts
		[2] => 5
		[3] => 5
	)
[31] => Array
	(
		[0] => 32
		[1] => hearts
		[2] => 6
		[3] => 6
	)
[32] => Array
	(
		[0] => 33
		[1] => hearts
		[2] => 7
		[3] => 7
	)
[33] => Array
	(
		[0] => 34
		[1] => hearts
		[2] => 8
		[3] => 8
	)
[34] => Array
	(
		[0] => 35
		[1] => hearts
		[2] => 9
		[3] => 9
	)
[35] => Array
	(
		[0] => 36
		[1] => hearts
		[2] => 10
		[3] => 10
	)
[36] => Array
	(
		[0] => 37
		[1] => hearts
		[2] => jack
		[3] => j
	)
[37] => Array
	(
		[0] => 38
		[1] => hearts
		[2] => queen
		[3] => q
	)
[38] => Array
	(
		[0] => 39
		[1] => hearts
		[2] => king
		[3] => k
	)
[39] => Array
	(
		[0] => 40
		[1] => spades
		[2] => ace
		[3] => a
	)
[40] => Array
	(
		[0] => 41
		[1] => spades
		[2] => 2
		[3] => 2
	)
[41] => Array
	(
		[0] => 42
		[1] => spades
		[2] => 3
		[3] => 3
	)
[42] => Array
	(
		[0] => 43
		[1] => spades
		[2] => 4
		[3] => 4
	)
[43] => Array
	(
		[0] => 44
		[1] => spades
		[2] => 5
		[3] => 5
	)
[44] => Array
	(
		[0] => 45
		[1] => spades
		[2] => 6
		[3] => 6
	)
[45] => Array
	(
		[0] => 46
		[1] => spades
		[2] => 7
		[3] => 7
	)
[46] => Array
	(
		[0] => 47
		[1] => spades
		[2] => 8
		[3] => 8
	)
[47] => Array
	(
		[0] => 48
		[1] => spades
		[2] => 9
		[3] => 9
	)
[49] => Array
	(
		[0] => 50
		[1] => spades
		[2] => jack
		[3] => j
	)
[50] => Array
	(
		[0] => 51
		[1] => spades
		[2] => queen
		[3] => q
	)
[51] => Array
	(
		[0] => 52
		[1] => spades
		[2] => king
		[3] => k
	)
)

 

 

Når du debugget så returnerte den en kortstokk etter du startet en runde. Riktig?

Sommerferien har virkelig ødelagt døgnrytmen min, så sliter litt med å finne hvilken linje der hvor feilen kan ligge. Kortenes verdi vises ikke når man oppretter kortstokk, kun når man blir med på runden..

Endret av KRIZx
Lenke til kommentar

Opprett en konto eller logg inn for å kommentere

Du må være et medlem for å kunne skrive en kommentar

Opprett konto

Det er enkelt å melde seg inn for å starte en ny konto!

Start en konto

Logg inn

Har du allerede en konto? Logg inn her.

Logg inn nå
×
×
  • Opprett ny...