2013-03-13

'Rock Paper Scissors' once again! - Just for fun!~

I would like to introduce you, the same, primitive game, called: 'Rock Paper Scissors'. Maybe, a little bit improved, in PHP this time.

<!DOCTYPE html>
<html>
<head>
<title>Paper, Scissors, Rock</title>
</head>
<body>
<h1>Paper, Rock, Scissors</h1>
<?php
if (isset($_GET['choice'])) {
$userChoice = strtolower($_GET['choice']);
$compChoice = rand(0, 99) / 100;
function comparison($choice1, $choice2) {
if ($choice1 == $choice2) {
return 'Yey! Draw! 1:1! <br /> <a href="gra.php">Back and play again</a>';
}
if ($choice1 == 'scissors') {
if ($choice2 == 'rock') {
return 'Computer won! <br /> <a href="gra.php">Back and play again</a>';
}
else {
return 'You won! <br /> <a href="gra.php">Back and play again</a>';
}
}
if ($choice1 == 'rock') {
if ($choice2 == 'scissors') {
return 'You won! <br /> <a href="gra.php">Back and play again</a>';
}
else {
return 'Computer won! <br /> <a href="gra.php">Back and play again</a>';
}
}
if ($choice1 == 'paper') {
if ($choice2 == 'rock') {
return 'You won! <br /> <a href="gra.php">Back and play again</a>';
}
else {
return 'Computer won! <br /> <a href="gra.php">Back and play again</a>';
}
}
}
if ($userChoice == 'paper' or $userChoice == 'rock' or $userChoice == 'scissors') {
if ($compChoice <= 0.34)
$compChoice = 'paper';
elseif ($compChoice <= 0.67)
$compChoice = 'scissors';
else
$compChoice = 'rock';
$Checker = comparison($userChoice, $compChoice);
echo $Checker;
} else {
echo 'You can choose only paper or scissors or rock <br />'.
'<a href="gra.php">Back and start again</a>';
}
}
else {
echo '<form method="GET">'.
'Choose your move: <input type="text" name="choice"/><br/>'.
'<input type="submit" value="OK"/>'.
'</form>';
}
?>
</body>
</html>
view raw game.php hosted with ❤ by GitHub

Brak komentarzy:

Prześlij komentarz

Dziękuję Ci za poświęcony czas i pozostawienie komentarza :)