BBGameZone.net PBBG Network | BuildingBrowserGames | Top-PBBG
March 11, 2010, 07:10:17 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Join the forums now, and start posting to receive access to our Scripts Vault!
 
  Home   Forum   Help Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Creating a simple "Guess the Number" game  (Read 1187 times)
Zeggy
Global Moderator
Level 35
*****

Reputation: 10
Offline Offline

Posts: 1,148



View Profile WWW
« on: December 23, 2006, 03:09:53 PM »

Here's a tutorial I wrote on how to create a Guess the Number game.
It's aimed for those who know basic PHP, and are still new to it. I've basically taken almost every line of code and explained what it does and why.
Please leave some comments Smiley

For the tutorial, please see the attachments.
« Last Edit: December 23, 2006, 03:16:15 PM by Zeggy » Logged
Karlos
Level 6
*

Reputation: 2
Offline Offline

Posts: 25


View Profile
« Reply #1 on: March 08, 2009, 12:34:20 PM »

Code:
<?php
$Message 
'';
if (isset(
$_POST['Submit'])) 
{
$Guess trim(intval($_POST['guess']));
$Random mt_rand('1''100');

if ($Guess '100' OR $Guess '1')
$Message 'Numbers Between 1-100 Only Please!';
else if (!ctype_digit($Guess))
$Message 'No Letters Fool!';
else if ($Guess == $Random)
$Message 'Congratulations!<br /> You Guessed The Correct Number: '.$Guess;
else
$Message 'Unlucky!<br /> You Guessed: '.$Guess.'! The Number was '.$Random;
}

echo 
'
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Guess The Number!</title>
<style type="text/css">
body {
background-color : #131c20;
font-family : Arial;
font-size : 15px;
color : #92aab8;
width : 405px;
}

div.LBox {
float : left;
width : 50px;
padding-right : 5px;
}

div.RBox {
clear : right;
}

img {
border : 0;
}
</style>
</head>
<body>
<div>
<h3>Guess The Number!</h3>
Numbers Are Between 1-100.<br /><br />'
;
echo sprintf("%s"$Message);
echo '
<br /><br />'
;
echo sprintf("<form method='post' action='%s'>"$_SERVER['PHP_SELF']);
echo '
<div class="LBox">Guess:</div>
<div class="RBox"><input type="text" name="guess" /><br /></div>

<div class="LBox">&nbsp;</div>
<div class="RBox"><input type="submit" value="Guess!" name="Submit" /></div>
</form>
<br />
<br />
<a href="http://validator.w3.org/check?uri=referer">
<img src="http://www.w3.org/Icons/valid-xhtml10-blue" alt="Valid XHTML 1.0 Strict" style="width:88px;height:31px" />
</a>
<a href="http://jigsaw.w3.org/css-validator/check/referer">
<img src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS!" style="width:88px;height:31px" />
</a>
</div>
</body>
</html>
'
;

?>

Bug Found & Fixed: Allowed You To Put A Number Then A Letter, Script Updated!

Functions I used:
« Last Edit: March 08, 2009, 01:22:48 PM by Karlos » Logged

Crazy-T
Level 19
*

Reputation: 0
Offline Offline

Posts: 197

Building Games


View Profile
« Reply #2 on: October 05, 2009, 03:33:29 AM »

Quote
Functions I used
Quote
echo()

As from the php Manual.
echo() is not actually a function Smiley
Logged

Crazy-T
Nox
Level 28
**

Reputation: 10
Offline Offline

Posts: 416



View Profile
« Reply #3 on: October 05, 2009, 06:27:01 AM »

Like it's essential Tongue
neither are isset, if/elseif/else, all are language constructs but in this case it's rather playing with words Wink
Logged

Bookmark worthy: Sirlin.net (game design)

Crazy-T
Level 19
*

Reputation: 0
Offline Offline

Posts: 197

Building Games


View Profile
« Reply #4 on: October 05, 2009, 06:34:02 AM »

Like it's essential Tongue
neither are isset, if/elseif/else, all are language constructs but in this case it's rather playing with words Wink
Haha lol i knew someone would post more :L
Logged

Crazy-T
Pages: [1]   Go Up
  Print  
 
Jump to:  


Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC
SimplePortal 2.2 © 2008-2009
Valid XHTML 1.0! Valid CSS!