BBGameZone.net PBBG Network | BuildingBrowserGames | Top-PBBG
September 03, 2010, 02:06:34 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Our Scripts Vault contains many game scripts that you can use to create your own game!
 
  Home   Forum   Help Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Creating a simple "Guess the Number" game  (Read 2233 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 7
*

Reputation: 2
Offline Offline

Posts: 31


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 31
**

Reputation: 10
Offline Offline

Posts: 526



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
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
SYKO
Level 3
*

Reputation: 0
Offline Offline

Posts: 9


View Profile
« Reply #5 on: July 13, 2010, 12:37:54 PM »

I can't download the Tutorial Attachment.
Can you re-upload it?
Logged
MystressNyx
Administrator
Level 14
*****

Reputation: 4
Offline Offline

Posts: 107



View Profile WWW
« Reply #6 on: July 13, 2010, 12:42:46 PM »

No, sorry. When we took over, we lost any previous attachments. Also, please do not use the report post function for anything other than to report forum violations.
Logged

SYKO
Level 3
*

Reputation: 0
Offline Offline

Posts: 9


View Profile
« Reply #7 on: July 13, 2010, 12:46:17 PM »

Also, please do not use the report post function for anything other than to report forum violations.

ahh, sorry for that.

btw, is there anyboy who can share the pdf file to me?
I saw that the file is downloaded 15 times. I think someone will share me.

Thanks
Logged
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!