Created
November 14, 2014 17:26
-
-
Save hansent/c029673ed1dccb682bca to your computer and use it in GitHub Desktop.
blackjack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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