<?php
header('Content-type: text/html; charset=utf8');
$cards = array();
$count = 0;
$buttonText = 'Start';
if (((isset($_POST['nextcard'])) && ($_POST['cards'])) || (isset($_POST['stop'])))
{
$cards = explode(',', $_POST['cards']);
$count = $_POST['count'];
if (($count >= 0) && (!isset($_POST['stop'])))
{
$count++;
$buttonText = 'Další karta';
}
}
else
{
$cards = array (
"♠2", "♣2", "♥2", "♦2",
"♠3", "♣3", "♥3", "♦3",
"♠4", "♣4", "♥4", "♦4",
"♠5", "♣5", "♥5", "♦5",
"♠6", "♣6", "♥6", "♦6",
"♠7", "♣7", "♥7", "♦7",
"♠8", "♣8", "♥8", "♦8",
"♠9", "♣9", "♥9", "♦9",
"♠10", "♣10", "♥10", "♦10",
"♠J", "♣J", "♥J", "♦J",
"♠Q", "♣Q", "♥Q", "♦Q",
"♠K", "♣K", "♥K", "♦K",
"♠A", "♣A", "♥A", "♦A",
);
shuffle($cards);
}
$cardsScore = array('J' => 10, 'Q' => 10, 'K' => 10, 'A' => 11);
$playerScore = 0;
echo('<table cellspacing="5"><tr>');
for ($i = 0; $i < $count; $i++)
{
echo('<td width="70px" height="100px" style="border:2px solid black; text-align:center;"><h1>' . $cards[$i] . '</h1></td>');
if (isset($_POST['stop']))
{
$card = str_replace(array('♠', '♣', '♥', '♦'), '', $cards[$i]);
if (is_numeric($card))
$playerScore += $card;
else
$playerScore += $cardsScore[$card];
}
}
echo('</tr></table>');
if (isset($_POST['stop']))
{
$computerScoreArray = array(16, 17, 18, 19, 20, 21, 'moc');
$computerScore = $computerScoreArray[rand(0, count($computerScoreArray) - 1)];
echo('Tvoje skóre: ');
if ($playerScore > 21)
echo('moc');
else
echo($playerScore);
echo('<br />Skóre počítače: ' . $computerScore . '<br />');
if ((is_numeric($computerScore) && ($computerScore >= $playerScore))
|| ($playerScore > 21))
echo('Vyhrál počítač');
else
echo('Vyhrál jsi ty!');
shuffle($cards);
$count = 0;
}
echo('
<form method="post">
<input type="hidden" name="cards" value="' . implode(',', $cards) . '" />
<input type="hidden" name="count" value="' . $count .'" />
<input type="submit" name="nextcard" value="' . $buttonText . '" />
<input type="submit" name="stop" value="Stop" />
</form>
');
Hra byla vytvořena v roce 2012.