Simple HTML Rock Paper Scissors Game - Play Now!
Rock, Paper, Scissors
<!-- create a form for the user's selection -->
<form action="">
<label for="selection">Choose Rock, Paper, or Scissors:</label>
<select name="selection" id="selection">
<option value="Rock">Rock</option>
<option value="Paper">Paper</option>
<option value="Scissors">Scissors</option>
</select>
<input type="submit" value="Submit" />
</form>
<?php
if (isset($_GET['selection'])) {
// get user's selection and the computer's random selection
$userSelection = $_GET['selection'];
$computerSelection = rand(0, 2);
// create an array of options
$options = array('Rock', 'Paper', 'Scissors');
// determine the winner
if ($userSelection == $options[$computerSelection]) {
echo '<h2>It's a tie!</h2>';
} elseif (($userSelection == 'Rock' && $options[$computerSelection] == 'Scissors') ||
($userSelection == 'Paper' && $options[$computerSelection] == 'Rock') ||
($userSelection == 'Scissors' && $options[$computerSelection] == 'Paper')) {
echo '<h2>You win!</h2>';
} else {
echo '<h2>You lose!</h2>';
}
}
?>
原文地址: https://www.cveoy.top/t/topic/lmlQ 著作权归作者所有。请勿转载和采集!