我尝试了许多不同的方法,但是没有用,我知道这是必需的
无法获得正确的使用顺序。
答案 0 :(得分:1)
您可以这样做:
$rs = 1;
$rslt = "Please select a strategy and press Play.";
$names = array("Rock", "Paper", "Scissors");
if (!isset($_GET['name'])) die("Name parameter missing");
if (isset($_POST['logout'])) {
header("Location: login.php");
return;
}
function play($h)
{
global $names;
$c = $names[rand(0, 2)];
if ($h === $c) $r = "Tie";
else if ($h === "Rock" && $c === "Scissors") $r = "You win.";
else if ($h === "Scissors" && $c === "Paper") $r = "You win.";
else if ($h === "Paper" && $c === "Rock") $r = "You win.";
else $r = "You lose.";
return "Your Play=$h Computer Play=$c Result=$r";
}
if (isset($_POST['option'])) {
if ($_POST['option'] === "Select") $rslt = "You must select a strategy in order to play.";
else if ($_POST['option'] === "Check") {
} else {
$rslt = play($_POST['option']);
}
}
?>
<html>
<head>
<title>Oscar Felipe Ramírez Pardo</title>
<meta charset="UTF-8">
</head>
<body>
<h1>Rock Paper Scissors</h1>
<p>Welcome: <?= htmlentities($_GET['name']) ?></p>
<form method="POST">
<select name="option">
<option value="Select" >Select</option>
<option value="Rock">Rock</option>
<option value="Paper">Paper</option>
<option value="Scissors">Scissors</option>
<option value="Check">Check</option>
</select>
<input type="submit" value="Play" name="dopost">
<input type="button" value="Logout" name="logout">
<p style="font-family:monospace">
<p>
<?= $rslt ?>
</p>
</p>
</form>
</body>
</html>