PHP摇滚,纸张,剪刀游戏错误

时间:2017-11-20 03:59:26

标签: php

rps.php

该程序的功能是允许玩家在摇滚,纸张和剪刀之间选择一个选项,然后将选择发送到第二页,该页面应显示其选项的图片,而不是随机计算机选项。 / p>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="keywords" content="Rock,Paper,Scissors">
<meta name="description" content="An automated game that plays rock,paper, 
scissors with you.">
<link rel="stylesheet" href="style.css" type="text/css">
<title>Rock Paper Scissors Game</title>
</head>
<body>
<h1>
Rock Paper Scissors Game
</h1>
<form action="rps2.php" method="get">
<p>
<input type="radio" name="player" value="1">Rock
<input type="radio" name="player" value="2">Paper
<input type="radio" name="player" value="3">Scissors
</p>
<p><input type="submit" value="Play"></p>
</form>
</body>
</html>

rps2.php

该程序的功能是根据选择显示哪个图像 玩家选择哪个选项并随机选择一张图片以供玩家所面对的计算机使用。问题是没有信息从第一页转移到下一页,验证并且表单操作指向正确的页面。

  <?php
    $player = 
    substr(filter_input(INPUT_GET,'player',FILTER_SANITIZE_NUMBER_INT),0,1);
    $computer = rand(1,3); #Rock 1, Paper 2, Scissors 3
    #Display Player/Visitor Hand
    if ($player == 1) 
    echo "<p><img src=\"rock1.png\" alt=\"image of rock\">";
    elseif ($player == 2)
    echo "<p><img src=\"paper1.png\" alt=\"image of paper\">";
    elseif ($player == 3)
    echo "<p><img src=\"scissors1.png\" alt=\"image of scissors\">";
    #Display Computer Hand
    if ($computer == 1) 
    echo "<p><img src=\"scissors2.png\" alt=\"image of scissors\">";
    elseif ($computer == 2)
    echo "<p><img src=\"rock2.png\" alt=\"image of rock\">";
    elseif ($computer == 3)
    echo "<p><img src\"paper2.png\" alt\"image paper\">";
    ?>

1 个答案:

答案 0 :(得分:0)

rps.php [程序1的正确代码]

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="keywords" content="Rock,Paper,Scissors">
<meta name="description" content="An automated game that plays rock,paper, scissors with you.">
<link rel="stylesheet" href="style.css" type="text/css">
<title>Rock Paper Scissors Game</title>
</head>
<body>
<h1>
Rock Paper Scissors Game
</h1>

<form action="rps2.php" method="get">
<p>
<input type="radio" name="player" value="1">Rock
<input type="radio" name="player" value="2">Paper
<input type="radio" name="player" value="3">Scissors
</p>
<p><input type="submit" value="Play"></p>
</form>
</body>
</html>

rps2.php [程序2的正确代码]

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="keywords" content="Rock,Paper,Scissors">
<meta name="description" content="The data from an automated game that plays rock,paper, scissors with you.">
<link rel="stylesheet" href="style.css" type="text/css">
<title>Rock Paper Scissors Game</title>
</head>
<body>
<h1>Rock Paper Scissors Game</h1>
<?php
$player = substr(filter_input(INPUT_GET,'player',FILTER_SANITIZE_NUMBER_INT),0,1);
$computer = rand(1,3); #Rock 1, Paper 2, Scissors 3
#Display Player/Visitor Hand
if ($player == 1) 
echo "<p><img src=\"rock1.png\" alt=\"image of rock\">";
elseif ($player == 2)
echo "<p><img src=\"paper1.png\" alt=\"image of paper\">";
elseif ($player == 3)
echo "<p><img src=\"scissors1.png\" alt=\"image of scissors\">";
#Display Computer Hand
if ($computer == 1) 
echo "<p><img src=\"scissors2.png\" alt=\"image of scissors\">";
elseif ($computer == 2)
echo "<p><img src=\"rock2.png\" alt=\"image of rock\">";
elseif ($computer == 3) 
echo "<p><img src=\"paper2.png\" alt=\"image paper\">"; 
?>
</body>
</html>