Guessing Game

This page is the home of the wonderful guessing game. How exciting!

This page is the home of the exciting number guessing game, where I pick a number and you try to figure out what it is. Would you like to play?

END; } else { $resend = 1; if($_POST['initial'] === "1") { // First load. Choose the number. $randno = rand(1,MAX_NUM); $guesscount = 0; $comment = ''; echo "

I'm thinking of a number between 1 and ", MAX_NUM, ". Can you guess it?

"; } else { // Not first load. Need to evaluate. $randno = $_POST['randno']; $guess = $_POST['guess']; $guesscount = $_POST['guesscount']; if($randno == $guess) { $start_form = 1; echo "

Congratulations! Your guess of $guess ", "is correct! Would you like to play again?

"; } else { if($guess < $randno - MAX_NUM / 2) { $comm = "way too small"; $comcl = "wts"; } elseif($guess < $randno) { $comm = "too small"; $comcl = "ts"; } elseif($guess > $randno + MAX_NUM / 2) { $comm = "way too large"; $comcl = "wtl"; } else { // Already checked if it matches exactly. $comm = "too large"; $comcl = "tl"; } echo "

No, your guess of $guess is $comm. "; // See if the game will continue. if($guesscount < GUESS_LIMIT) { echo "Care to try again? You have ", GUESS_LIMIT-$guesscount, " guesses left.

"; } else { echo "

I'm sorry, you have used all ", "of your ", GUESS_LIMIT, " guesses. The number ", "I was thinking of was $randno. Would you like ", "to try again?

"; $start_form = 1; } } } } // Game continues. Generate the correct form. $me = $_SERVER['PHP_SELF']; if($start_form) { echo << END; } else { ++$guesscount; echo << END; } ?>