Skip to content

Instantly share code, notes, and snippets.

@hansent
Created November 14, 2014 17:26
Show Gist options
  • Save hansent/c029673ed1dccb682bca to your computer and use it in GitHub Desktop.
Save hansent/c029673ed1dccb682bca to your computer and use it in GitHub Desktop.
blackjack
<?php
$player_hand = array();
$dealer_hand = array();
//init and shuffle deck of cards
$deck = glob('cards/*.png');
shuffle($deck);
//give two cards to player and dealer each
for($i=0; $i<2; $i++){
array_push($dealer_hand, array_pop($deck ));
array_push($player_hand, array_pop($deck ));
}
//render html for a hand of cards
function render_hand($hand){
echo "<div class='hand'>";
foreach($hand as $card){
echo "<img src='$card'>";
}
echo "</div>";
}
?><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Blackjack</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>Dealer:</h1>
<?php render_hand($dealer_hand) ?>
<h1>Player:</h1>
<?php render_hand($player_hand) ?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment