//Guessing Game by Stuart Coutchie
//Reversed Polarity WebDesign
//www.reversedpolarity.com
//
//Feel free to use this to your advantage!
//
<html>
<head>
</head>
<body>
<center>
<font face="Arial Black" size="3">Guessing Game</font>
</center>
<hr>
<?php
if ($play == "play") {
//setting the random numbers
//computers guess
srand ((double) microtime() * 1000000);
$myguess = rand (0,20);
//real answer
srand ((double) microtime() * 1000000);
$thevalue = rand (0,20);
//displaying the guesses from the previous results
echo "Your last guess was: ";
echo $guess;
echo "n<br>";
echo "My last guess was: ";
echo $myguess;
echo "n<br>";
echo "<br>";
echo "The right answer was: ";
echo $thevalue;
echo " n";
echo "<br>";
echo $message;
echo " n";
//setting the difference of the guesses vs the real answer
$yourdiff=$guess-$thevalue;
$yourdiffcorrected=abs($yourdiff);
$mydiff=$myguess-$thevalue;
$mydiffcorrected=abs($mydiff);
//adding up the scores
if ($yourdiffcorrected>$mydiffcorrected)
{
$myscore=$points+$myscore;
$yourscore=0+$yourscore;
$message="I won the points";
}
if ($yourdiffcorrected<$mydiffcorrected)
{
$yourscore=$points+$yourscore;
$myscore=0+$myscore;
$message="You won the points";
}
if ($yourdiffcorrected==$mydiffcorrected)
{
$yourscore=$points+$yourscore;
$myscore=$points+$myscore;
$message="We tied, so we both get points";
}
echo "<br>";
echo $message;
echo " n";
}
?>
<br><br>
Closest to a number wins points
<br>
<?php
echo "<form action="$PHP_SELF?action=direct">";
?>
Lets play for how many points?
<br>
<?php
echo "<INPUT TYPE="text" NAME="points" SIZE="10" value="".$points."">";
?>
<br>
<br>
Guess a number between 0 and 20
<br>
<input type="text" name="guess" size="10">
<?php
echo "<input type="hidden" name="yourscore" value="".$yourscore."">n";
echo "<input type="hidden" name="myscore" value="".$myscore."">n";
echo "<INPUT TYPE="submit" NAME="play" VALUE="play">n";
echo "</FORM>n";
?>
<?php
//setting the message telling who is winning
if ($play == "play") {
if ($myscore==$yourscore){
$mymessage="We're Tied";
$yourmessage="We're Tied";
}
if ($myscore>$yourscore){
$mymessage="I'm winning";
$yourmessage="Your losing";
}
if ($myscore<$yourscore){
$yourmessage="Your winning";
$mymessage="I'm losing";
}
//displaying the table showing the scores
echo " <table border="1" width="450">n";
echo "<tr>n";
echo "<td width="50"><font face="Arial Narrow" size="1">ME</font></td>n";
echo "<td width="50"><font face="Arial Narrow" size="1">";
echo $myscore;
echo "</font></td>n";
echo "<td width="250"><img src="red.jpg" height="10"width="".$myscore.""></td>n";
echo "<td width="150">".$mymessage."</td>n";
echo "</tr>";
echo "<tr>n";
echo "<td width="50"><font face="Arial Narrow" size="1">You</font></td>n";
echo "<td width="50"><font face="Arial Narrow" size="1">";
echo $yourscore;
echo "</font></td>n";
echo "<td width="250"><img src="blue.jpg" height="10"width="".$yourscore.""></td>n";
echo "<td width="150">".$yourmessage."</td>n";
echo "</tr>";
echo "</table>";
//resetting the form if you want to start over
//by setting the play variable to something other than 'play'
echo "<form action="$PHP_SELF?action=direct">";
echo "<input type="submit" name="play" value="Start Over">";
}
?>
</body>
</html>
|