[wap] Rock-paper-scissors For Lavalair
Started on the old forum in July 2008 · view the original in the archive · old links redirect here
22 replies · 2,769 views · started 18 years ago · 3 min read
TL;DR · summary of 22 replies
- The code did not work due to a missing file named "rps.php".
- The file needed to be uploaded to the web folder.
- To resolve, the file should be renamed from whatever name it was given to "rps.php".
Written automatically from the replies by a language model on our own server. It can be wrong; the posts below are the source.
WI
QUOTE (rukiya @ Jan 11 2009, 05:43 AM) <{POST_SNAPBACK}>
It can be coded in short by applying some maths in it like
<?php
/*****************
Rock , Paper , Scissors Game
By
DNS
http://forum.wapfuns.com
******************/
$choice = $_POST["choice"];
if($choice!="")
{
$select = array ("Rock" , "Paper" , "Scissors");
$computer = rand(0,2);
echo "You chose $select[$choice] .
";
echo "Computer chose $select[$computer] .
";
$result = $choice - $computer;
if($result == 1 || $result == -2)
{
echo "You Win :)";
}
else if($result==0)
{
echo "Draw !";
}
else
{
echo "You lose :(";
}
exit();
}
?>
<html>
<head><title> Rock Paper Scissors Game By DNS</title></head>
<body>
Choose
<form action ="<?php $PHP_SELF;?>" method="post">
<select name ="choice">
<option value ="0" selected>Rock</option>
<option value ="1">Paper</option>
<option value ="2">Scissors</option>
</select>
<input type="submit" value="Play">
</form>
</body>
</html>
kool, but this works differently
WA
CR
Oh f.c.o.l save a lot of coding, at least make ur script neat.
function rpsResult($bet1,$bet2){
//bet1 is person dat accepts d challenge
if($bet1==$bet2){ return 0; }//draw
if(($bet1==1 && $bet2==2) || ($bet1==2 && $bet2==3) || ($bet1==3 && $bet2==1)){ return 2; }//bet1 lost, bet2 won
if(($bet1==1 && $bet2==3) || ($bet1==2 && $bet2==1) || ($bet1==3 && $bet2==2)){ return 1; }//bet2 lost, bet1 won
}
usage
betcodes
- 1 = paper
- 2 = scissors
- 3 = rock
pseudo code
if(rpsResult($challengedsBet,$challengersBet) == 0){ echo "RESULT TIE"; }elseif(rpsResult($challengedsBet,$challengersBet) == 1){ echo "RESULT: YOU WIN"; }elseif(rpsResult($challengedsBet,$challengersBet) == 2){ echo "RESULT: YOU LOST"; }