Posted by: spawnfestis on: March 24, 2009
default.php
Create a form with the name “guessedNum”, it should be an input form, and it should refer to guessgame.php
guessgame.php
<?php
// Declarations
$randNum = mt_rand(1,5);// $_POST['nameofpostedarea'] returns what you sent from the default.php file,
// thus how you can use it to build a simple game
echo “You guessed “.$_POST['guessedNum'].”.“;
if ($_POST['guessedNum'] == $randNum) {
echo “And you won! The right number was indeed “.$_POST['guessedNum'].” !“;
}
else if($_POST['guessedNum'] > 5 || $_POST['guessedNum'] < 0) { // If the user tries to break the rules
echo “Omg. I said between 1-5 which means “.$_POST['guessedNum'].” is invalid..“;
} else {
echo “But you lost.. because the right number was “.$randNum.”“;
}
?>
Seems like something very basic.
March 29, 2009 at 8:03 pm
Det hade varit mer awesome om du gjorde så att det var samma nummer tills man gissade rätt / startade en ny runda.
Otherwise great progress!
March 31, 2009 at 12:31 pm
Haha
I’ve made even more progress. What I put up on the testside was all done within a few hours, which makes me remember – Oh! Programming in a new language is way too easy when you know another language :- )