Working on a php guessing game, and stuck! Please help!?

Slinky

New member
I'm currently taking a intro php class and our project involves making a number guessing game. Here are the instructions: Create a game where a person chooses a number 1-100. Your program guesses the number within 7 guesses. Your program will display a guess and a running count of the number of guesses. User tells program: higher, lower or correct after each guess. Your program also makes "very confident" "remarks" along with each guess, because you know you will win.

Here is what I have so far :

<html>
<head>
<title>
Number Game
</title>
</head>
<body>
<h1>"Think of a number between 1 and 100. I can guess your number in 7 guesses or less. When you are ready to be amazed click "start Game"</h1>

<form method='post'
action=''>
<input type='submit'name='start'id='start' value='Start Game'
method='post' action=''>
<input type='submit' name='higher' id='start' value='Higher'
method='post' action=''>
<input type='submit' name='lower' id='start' value='Lower'
method='post' action=''>
<input type='submit' name='correct' id='start' value='Correct'>

<?php

$nguess[1] = "I'm going to win";
$nguess[2] = "You cant beat me";
$nguess[3] = "I never lose";
$nguess[4] = "Don't be surprised if I guess your number";
$nguess[5] = "I don't know what it feels like to lose";
$nguess[6] = "Something is seriously wrong if I lose this";
$nguess[7] = "Seven tires is all it takes for me to win";

if (isset($_POST['start'])) {
$count = 1;
$g= 50;
$top = $_POST["hdntop"];
$bottom = $_POST["hdnbottom"];
print "<br>Is this your number $g\n";

} else if(isset($_POST['higher'])) {
$count = $_POST["hdnCount"] + 1;
$top = $_POST["hdntop"] = 100;
$bottom = $_POST["hdnbottom"] = 50;
$g = $_POST["hdnguess"] = round(($top + $bottom))/2;
$random = array_rand($nguess);
$randomcomments = $nguess[$random];
echo $randomcomments;

print "<br>Is this your number $g\n";
print "<br>$count\n";

} else if(isset($_POST['lower'])) {
$count = $_POST["hdnCount"] + 1;
$top = $_POST["hdntop"] = 50;
$bottom = $_POST["hdnbottom"] = 0;
$g = $_POST["hdnguess"] = round(($bottom + $top))/2;
$random = array_rand($nguess);
$randomcomments = $nguess[$random];
echo $randomcomments;
print "<br>Is this your number $g\n";
print "<br>$count\n";

} else if(isset($_POST['correct'])) {
$g = 50;
$top = 100;
$bottom = 0;
$count = 1;
print "I told you I would win";
print "<br>";
}
print <<< HERE
<input type = 'hidden' name = 'hdnCount' value = $count>
<input type = 'hidden' name = 'hdntop' value = $top>
<input type = 'hidden' name = 'hdnbottom' value = $bottom>
<input type = 'hidden' name = 'hdnguess' value = $g>
HERE;

?>

</form>

</body>

</html>
 
Back
Top