PHP滚动骰子猜测

时间:2014-06-16 20:47:03

标签: php

我是php的新手,我无法让我的程序正确显示。如果代码不起作用,我就不会得到像Great Job这样的文字,你很好! 我只是想做一个简单的猜谜游戏,你猜数字,你会看到你猜对了正确的数字肯定随机数。

这是我的代码(php.html)

        <html>
        <head>
        </head>
                 <body>

         <form name = "Dice roller" action="game_check.php" method="post">

           Your guess: <br>

         <input type= "text" name="" size= "1">

       <input type ="submit" name = "submit">

      </form>
     </body>
        </html>

Game_check.php

    <html>
      <body>
         <?php
        $roll = $_POST['submit']; 
        $dice =  rand(1, 6);

        if ($roll == 1 && $dice == 1) 
       { 
          print "Great Job, You're Good!"; 
       }
       else if ($roll == 1 && $dice /= 1) 
       {
             print "Wrong"; <br >
       }



       if($dice == 1) print "<img src='1.png'>"."<br>";
       if($dice == 2) print "<img src='2.png'>"."<br>";
       if($dice == 3) print "<img src='3.png'>"."<br>";
       if($dice == 4) print "<img src='4.png'>"."<br>";
       if($dice == 5) print "<img src='5.png'>"."<br>";
       if($dice == 6) print "<img src='6.png'>"."<br>";

               else {
                  print "Thanks". "<br>";
            }

            ?>

       <form name= "Back" action= "php.html" method= "post"> 
       <input type="submit" name="back" value ="Play again">
        </form>
        </body>
        </html>

我有6个骰子的if循环.. 谢谢

3 个答案:

答案 0 :(得分:1)

您的if陈述是错误的,您只需要。您还需要休息一下,进入print

if ($roll == $dice) 
{ 
    print "Great Job, You're Good!"; 
} else {
    print "Wrong<br />";
}

答案 1 :(得分:1)

请务必使用正确的语法。如果要检查两个对象是否不相等,则运算符如下所示:

a != b

答案 2 :(得分:1)

更改此行:

else if ($roll == 1 && $dice /= 1) 

else if ($roll == 1 && $dice != 1)