Hello, I was bored and made this for fun.
It's kinda sad
Play Stone, Paper, Scisser against the Computer!
DEMO: http://xcoderz.net/examples/sps.php
Source:
It's kinda sad
Play Stone, Paper, Scisser against the Computer!
DEMO: http://xcoderz.net/examples/sps.php
Source:
PHP:
<?php
// Stone/Paper/Scissor v1
// SPS.PHP - Coded by l0calh0st!
function play($play_1, $play_2, $won = array(1, 2, 0)){
return ($play_1 != $play_2) ? ($won[$play_1] == $play_2) ? 1 : 0 : 2 ;
}
if (isset($_POST['submit'])){
$you = $_POST['keuze'];
$computer = rand(0, 2);
echo '<strong>';
echo 'The computer had ';
if ($computer == 0){
echo 'stone';
}elseif ($computer == 1){
echo 'scissor';
}elseif ($computer == 2){
echo 'paper';
}
echo ' and you had ';
if ($you == 0){
echo 'stone';
}elseif ($you == 1){
echo 'scissor';
}elseif ($you == 2){
echo 'paper';
}
echo '</strong>';
echo '<br /><br />';
if(play($you, $computer) == 0){
echo '<span style="color: red;">LOST!</span>';
}elseif(play($you, $computer) == 1){
echo '<span style="color: green;">WON!</span>';
}elseif(play($you, $computer) == 2){
echo '<span style="color: black;">DRAW!</span>';
}
echo '<br /><br />';
echo '<a href="' . $_SERVER['PHP_SELF'] . '">Play again!</a>';
}else{
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<h3><em>Stone, Paper, Scissor!</em></h3>
Make your choice:
<select name="keuze">
<option value="0">Stone</option>
<option value="1">Scissor</option>
<option value="2">Paper</option>
</select>
<br /><br />
<input type="submit" name="submit" value="Play!">
</form>
<?php
}
?>