PBBG Network
|
BuildingBrowserGames
|
Top-PBBG
September 03, 2010, 02:06:34 AM
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email?
1 Hour
1 Day
1 Week
1 Month
Forever
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
BBGameZone.net
>
Webmasters
>
The Articles
>
Creating a simple "Guess the Number" game
Pages: [
1
]
Go Down
« previous
next »
Print
Author
Topic: Creating a simple "Guess the Number" game (Read 2233 times)
Zeggy
Global Moderator
Level 35
Reputation: 10
Offline
Posts: 1,148
Creating a simple "Guess the Number" game
«
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
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
Posts: 31
Re: Creating a simple "Guess the Number" game
«
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"> </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:
Varibles
isset()
trim()
intval()
$_POST()
mt_rand()
if()
else if()
else()
ctype_digit()
Operators
echo()
sprintf()
$_SERVER
«
Last Edit: March 08, 2009, 01:22:48 PM by Karlos
»
Logged
My Twitter!
Crazy-T
Level 19
Reputation: 0
Offline
Posts: 197
Building Games
Re: Creating a simple "Guess the Number" game
«
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
Logged
C
r
a
z
y
-
T
Nox
Level 31
Reputation: 10
Offline
Posts: 526
Re: Creating a simple "Guess the Number" game
«
Reply #3 on:
October 05, 2009, 06:27:01 AM »
Like it's essential
neither are isset, if/elseif/else, all are language constructs but in this case it's rather playing with words
Logged
Crazy-T
Level 19
Reputation: 0
Offline
Posts: 197
Building Games
Re: Creating a simple "Guess the Number" game
«
Reply #4 on:
October 05, 2009, 06:34:02 AM »
Quote from: Nox on October 05, 2009, 06:27:01 AM
Like it's essential
neither are isset, if/elseif/else, all are language constructs but in this case it's rather playing with words
Haha lol i knew someone would post more :L
Logged
C
r
a
z
y
-
T
SYKO
Level 3
Reputation: 0
Offline
Posts: 9
Re: Creating a simple "Guess the Number" game
«
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
Posts: 107
Re: Creating a simple "Guess the Number" game
«
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
Posts: 9
Re: Creating a simple "Guess the Number" game
«
Reply #7 on:
July 13, 2010, 12:46:17 PM »
Quote from: MystressNyx on July 13, 2010, 12:42:46 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
« previous
next »
Jump to:
Please select a destination:
-----------------------------
BBGameZone
-----------------------------
=> Announcements
=> Help, Suggestions & Feedback
=> Introductions
-----------------------------
Webmasters
-----------------------------
=> The Starting Line
=> The Articles
=> Coding Discussion
===> Code Help
=> Game Design
=> Game Management
=> Web Design & Graphics
=> Revenue & Promotion
=> Hosting & Domains
=> General Game Discussion
===> Text Games
===> Flash Games
===> Java Games
===> Other Games
-----------------------------
Advertise
-----------------------------
=> Projects
=> Advertisements
=> Marketplace
===> Scripts
===> Employment
===> Webmaster Exchanges
===> Advertisements
-----------------------------
Other Stuff
-----------------------------
=> General Chat & Entertainment
=> Archive
===> PBBG Contest #1
=====> Entries
Loading...