-1

我正在制作一个小游戏,只有当套装和号码与随机选择的号码和套装匹配时才会显示卡片。代码如下:

<?php



$suite['heart'] = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13);
$suite['spade'] = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13);
$suite['diamond'] = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13);
$suite['club'] = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13);

    $suit1 = array_rand($suite);
    $suit2 = array_rand($suite); 

    $card1 = array_rand($suite[$suit1]);
    $card2 = array_rand($suite[$suit2]);

    $card_1 = $suite[$suit1][$card1];
    $card_2 = $suite[$suit2][$card2];

    function jqk($n){
            if($n == 11 && $suit1 == 'club'){
                  return "<img src='img/clubs_J.png'>";
                } else{
                  return "J";
                }


            else if ($n==12){
                return 'Q';
            }
            else if ($n==13){
                return 'K';
            } else {
            return $n;
            }
        }

    if($card_1 <= $card_2){
            $lowcard = $card_1;
            print "The Low Card is ".jqk($lowcard)."<br />";
        } elseif ($card_1 >= $card_2){
            $highcard = $card_1;

            print "The High Card ".jqk($highcard)."<br />";
        }

        if($card_1 <= $card_2){
            $highcard = $card_2;

            print "The High Card is ".jqk($highcard)."<br />";
        } elseif ($card_1 >= $card_2){
            $lowcard = $card_2;

            print "The Low Card ".jqk($lowcard)."<br />";
        }

?>

我的问题是,输出绕过了对 $suit1 的检查,并且所有匹配 11 的数字都显示了图像。先感谢您

4

1 回答 1

0

你的jqk()功能有问题。我想知道你怎么能运行那个功能。这里有语法错误

else if ($n==12){ //else pops in without if

试试这个:

function jqk($n){
      global $suit1;            
      if( $n == 11 ){
        if( $suit1 == 'club' ){
          return "<img src='img/clubs_J.png'>";
        } else{                
          return "J";
        }
      } else if ( $n == 12 ){
        return 'Q';
      } else if ( $n == 13 ){
        return 'K';
      } else {
        return $n;
     }
}
于 2013-09-18T04:52:31.447 回答