Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- enforce_login();
- session_start();
- if(!check_perms('site_play_blackjack')) error(403);
- show_header('Blackjack','');
- if(!isset($_SESSION['betAmount'])) {
- $BetAmount = false;
- } else $BetAmount = $_SESSION['betAmount'];
- if(isset($_POST['setBet'])) {
- $_SESSION['betAmount'] = $_POST['submit'];
- $BetAmount = $_POST['submit'];
- }
- /* First, we have the suits */
- $suits = array (
- "s", "h", "c", "d"
- );
- /* Next, we declare the faces*/
- $faces = array (
- "2"=>2, "3"=>3, "4"=>4, "5"=>5, "6"=>6, "7"=>7, "8"=>8,
- "9"=>9, "10"=>10, "11"=>10, "12"=>10, "13"=>10, "14"=>11
- );
- // INI. some vars
- $bust = false;
- $dealerBust = false;
- $gameEnd = false;
- function evaluateHand($hand) {
- global $faces;
- $value = 0;
- foreach ($hand as $card) {
- if ($value > 11 && $card['face'] == '14') {
- // There's a bug here. If you draw Ace-Five-Ace-Ten, it thinks you have 27.
- // Have a go at fixing that bug. Email me if you have problems. - DPO
- $value = $value + 1;
- } else {
- $value = intval($value) + intval($faces[$card['face']]);
- }
- }
- return $value;
- }
- /* Now build the deck by combining the faces and suits. */
- $deck = array();
- foreach ($suits as $suit) {
- $keys = array_keys($faces);
- foreach ($keys as $face) {
- $deck[] = array('face'=>$face,'suit'=>$suit);
- }
- }
- /* Next, you can shuffle up the deck and pull a random card. */
- shuffle($deck);
- $hand = array();
- ?>
- <div class='thin'>
- <h2>Blackjack</h2>
- <div class="head center"> Disclaimer </div>
- <div class="box pad">
- <b>NOTE:</b><br/>
- Når du loader Den enarmede Tyveknægt, så laver den en cacheudgave af dine Bones. Når siden forlades eller lukkes ned, opdateres de. Ikke før. UnderDawgs.biz har INTET ansvar for evt. tab af Bones ved brug af dette script!!!<br>
- Bet er antal Bones du byder pr. spil.
- </div>
- <div class='head center'>Blackjack</div>
- <div class='box pad'>
- <a name='game'></a>
- <?
- if($BetAmount != false) {
- if (empty($_POST['runGame'])) {
- for ($i = 0; $i < 2; $i++) {
- $hand[] = array_shift($deck);
- $dealer[] = array_shift($deck);
- }
- $handstr = serialize($hand);
- $deckstr= serialize($deck);
- $dealerstr= serialize($dealer);
- } else if ($_POST['submit'] == 'stay') {
- $dealer = unserialize($_POST['dealerstr']);
- $hand = unserialize($_POST['handstr']);
- $deck = unserialize($_POST['deckstr']);
- while(evaluateHand($dealer) < 17) {
- $dealer[] = array_shift($deck);
- }
- if(evaluateHand($dealer) > 21) $dealerBust = true;
- if(evaluateHand($hand) > 21) $bust = true;
- $gameEnd = true;
- if(!$dealerBust) echo "Dealer hit " . evaluateHand($dealer) . "<br />"; else echo "Dealer Busted<br/>";
- if(!$bust) echo "You hit " . evaluateHand($hand) . "<br /><br/>"; else echo "You Busted<br/><br/>";
- $handstr = $_POST['handstr'];
- $dealerstr = serialize($dealer);
- $deckstr= serialize($deck);
- } else if ($_POST['submit'] == 'hit me') {
- $dealer = unserialize($_POST['dealerstr']);
- $hand = unserialize($_POST['handstr']);
- $deck = unserialize($_POST['deckstr']);
- $hand[] = array_shift($deck);
- $dealerstr = $_POST['dealerstr'];
- $handstr = serialize($hand);
- $deckstr= serialize($deck);
- }
- ?>
- <form method='post' action='?action=blackjack#game'>
- <input type='hidden' name='runGame' value='true'>
- <input type='hidden' name='checksum' value='<?php echo $checksum ?>'>
- <input type='hidden' name='handstr' value = '<?php echo $handstr ?>' />
- <input type='hidden' name='deckstr' value = '<?php echo $deckstr ?>' />
- <input type='hidden' name='dealerstr' value = '<?php echo $dealerstr ?>' />
- <?php
- foreach ($hand as $index =>$card) {
- echo "<img src='/static/common/bj_cards/". $card['suit'] . $card['face'] .".gif' />";
- }
- if(evaluateHand($hand) > 21) $bust = true;
- if(!$bust) {
- ?>
- <p>You have : <?php echo evaluateHand($hand); ?></p>
- <?php } else echo "<p>You Busted</p>"; ?>
- <p>
- <?php if(!$gameEnd) { ?>
- Dealer is showing:<br/>
- <?php echo "<img src='/static/common/bj_cards/". $dealer[0]['suit'] . $dealer[0]['face'] .".gif' />"; ?><img src='/static/common/bj_cards/back.gif' />
- <?php } else {
- foreach ($dealer as $index =>$card) {
- echo "<img src='/static/common/bj_cards/". $card['suit'] . $card['face'] .".gif' />";
- }
- } ?>
- </p>
- <?php
- if($bust) $gameEnd = true;
- if($dealerBust) $gameEnd = true;
- if(!$gameEnd) {
- ?>
- <input type='submit' name='submit' value='hit me' />
- <input type='submit' name='submit' value='stay' /><br/>
- </form>
- <?php
- } else {
- $_SESSION['betAmount'] = false;
- $player = evaluateHand($hand);
- $dealer = evaluateHand($dealer);
- if(!$bust) {
- if(!$dealerBust) {
- if($player > $dealer) $win = 'player'; else $win = 'dealer';
- } else $win = 'player';
- } else $win = 'dealer';
- if($win == 'player') {
- echo "You Win!";
- } elseif($win == 'dealer') {
- echo "You Loose!";
- } else echo "ERROR";
- echo " <a href='bonus.php?action=blackjack'>Prøv Igen?</a>";
- }
- } else {
- ?>
- Choose your bets:
- <form method='post'>
- <input type='hidden' name='setBet' value='true'>
- <input type='submit' name='submit' value='10'>
- <input type='submit' name='submit' value='50'>
- <input type='submit' name='submit' value='100'>
- Bones
- </form>
- <?
- }
- ?>
- </div>
- </div>
- <?
- show_footer();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement