PHP-在会话中挣扎

时间:2018-11-07 16:16:18

标签: php session blackjack

我正在尝试制作一个php二十一点游戏,但是我在努力使用会话。我的目标是随机挑选2张卡片,并在屏幕上显示所选择卡片的图像。我可以在屏幕上显示一张卡,但是我无法弄清楚如何同时显示第二张卡,然后在需要时显示第三张卡。我将发布我已经拥有的代码。任何帮助表示赞赏。

  <?php
    session_start();
    $suits = array('Clubs', 'Diamonds', 'Hearts' ,'Spades');
    $cards = array('2' => 2, '3' => 3, '4' => 4, '5 '=> 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, '10' => 10, 'Jack' => 10, 'Queen' => 10 ,'King' => 10 ,'Ace '=> 11);

     $hand = array();

    $cardNum = rand(1, 52);

    $theCard = $cards [$cardNum % 13];

    $theTrump = $suits[floor ($cardNum / 13)];

    echo '<br> the card selected was ' . $theCard . ' of '. $theTrump;

    echo '<img src= '. $theCard .'_of_'. $theTrump  . '.png >';

    array_push($hand,  "$theCard");

   print_r($hand);

   $_SESSION[card]=$cards;

    foreach ($_SESSION[card] as $key=> $value) {
     echo 'Total score is'.$value.':';
      }



     ?>

    <form>
      <input type="button" onclick="history.go(0)" value="Hit">
    </form>

0 个答案:

没有答案