Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Creating a "Guess the Number" Game
Old 10-16-2007, 03:02 PM Re: Creating a "Guess the Number" Game
MGT-Evelath's Avatar
Average Talker

Posts: 21
Trades: 0
Thanks for all the assistance, now I'm working on doing the reverse (along with a few other PhP-related items which I'll bring up after i've tackled the following two:

First - I'm trying to write the same game, but in reverse. Where the user guesses a number, and the computer guesses it. The computer should be able to guess the answer in 7 attempts if the user correctly uses the right buttons:

PHP Code:
<html>

<head>

<title>

Reverse "Thinking of a Number"

</title>

</head>

<body>

<form action="<?php $_SERVER['PHP_SELF']?>" method="post">
<?

//check to see if this is the first time here
$GuessNumber $_POST['GuessNumber'];

if (
$_POST['Correct'])
{
echo 
"The Computer Succeeded!"
}

//HTML Forms
print <<<HERE

<input type = "hidden"
       name = "GuessNumber"
       value = "<?php echo(
$GuessNumber); ?>"">

<input type = "submit"
       value = "Too High">
<input type = "submit"
       value = "Too Low">
<input type = "submit"
       value = "Correct">

$GuessNumber

HERE;


?>
</form>


</body>

</html>
Obviously it isn't finished yet, however I am looking for assistance. Compared to my posts above, I am curious as to how I would go about this. I believe it would look something like this:

1) Assign a random number to a value.
2) Depending on whether the user selects "Too High", or "Too Low", would depend on the change in the number. ((How would that look in code?))
3) Finally finishing in seven steps.

Second - Alright, after that I am attempting to build a 'poker hand', which randomly deals out five cards to the player. I have the images I need, I just need to get the coding perfect. A few hints are all I need for this one:

1) How would I assign the images//cards to a certain value?
2) Randoming the cards I don't understand how that would be processed or explained via PhP.

PS: Thanks for all the assistance with the project above. Any further help would be appreciated.

Last edited by MGT-Evelath; 10-16-2007 at 03:11 PM..
MGT-Evelath is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-16-2007, 03:51 PM Re: Creating a "Guess the Number" Game
dansgalaxy's Avatar
Defies a Status

Posts: 6,522
Name: Dan
Location: Swindon
Trades: 0
interesting idea i like it

Okay lets see

Well i think you would do it as a elseif on your if correct stament

so it does something like if too high
half the number it guessed

and if too low double the number etc...

Should be quite simple now i think about it.

Im gonna have a bas now so ill post it in a bit
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 10-16-2007, 04:38 PM Re: Creating a "Guess the Number" Game
dansgalaxy's Avatar
Defies a Status

Posts: 6,522
Name: Dan
Location: Swindon
Trades: 0
You know what i lied this is harder than i thought. im going to have another go but it will use a database table.

Dan
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 10-16-2007, 04:41 PM Re: Creating a "Guess the Number" Game
MGT-Evelath's Avatar
Average Talker

Posts: 21
Trades: 0
Yeah, when I saw this I thought it would be easy to understand after the last php code that you assisted me with. However after trying a few ways it seems a lot more complicated than I thought.

Could I merely use a "hidden" number, then based on the choices of the user move that number up or down depending on 'too low' or 'too high' ?
MGT-Evelath is offline
Reply With Quote
View Public Profile
 
Old 10-16-2007, 06:13 PM Re: Creating a "Guess the Number" Game
dansgalaxy's Avatar
Defies a Status

Posts: 6,522
Name: Dan
Location: Swindon
Trades: 0
ok its much harder than i thought so im gonna have to do a lot more but im tired so tomorrow....
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 10-17-2007, 07:13 AM Re: Creating a "Guess the Number" Game
Galaxian's Avatar
Dingleberry!

Posts: 825
Name: Rich
Location: United Kingdom
Trades: 0
I mean you could disguise the number in md5 in a hidden form element, but probably some sad person could use an md5 checker and go through all the numbers until he has that one.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Galaxian is offline
Reply With Quote
View Public Profile Visit Galaxian's homepage!
 
Old 10-17-2007, 05:35 PM Re: Creating a "Guess the Number" Game
goheadtry's Avatar
Webmaster Talker

Posts: 726
Name: John
Location: United States of America, California
Trades: 0
This is how I would do this I think this should help you. Talkupation would be greatly appreciated.



PHP Code:
<HTML>
<HEAD>
<TITLE>Number Game</TITLE>
</HEAD> 
<BODY>
<?php // Name this file number.php ?>
<form action="number.php" method="post">
Enter your name: <input type="text" name="number" />
<input type="submit" />
</form>

<?php
$secret 
'12';
if (
$_POST["number"] == $secret ) {
    echo 
"You guessed correctly";
} else {
    echo 
"You did not guess the secret number";
}
?>
<p>
<A>HREF="http://www.technologyforever.com">Click here to go to the TechnologyForever.com</A> 
</p>
</BODY>
</HTML>
__________________
Free $1 gift card when you signup at
Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

goheadtry is offline
Reply With Quote
View Public Profile Visit goheadtry's homepage!
 
Old 10-18-2007, 04:30 PM Re: Creating a "Guess the Number" Game
MGT-Evelath's Avatar
Average Talker

Posts: 21
Trades: 0
Quote:
Originally Posted by goheadtry View Post
This is how I would do this I think this should help you. Talkupation would be greatly appreciated.



PHP Code:
<HTML>
<HEAD>
<TITLE>Number Game</TITLE>
</HEAD> 
<BODY>
<?php // Name this file number.php ?>
<form action="number.php" method="post">
Enter your name: <input type="text" name="number" />
<input type="submit" />
</form>

<?php
$secret 
'12';
if (
$_POST["number"] == $secret ) {
    echo 
"You guessed correctly";
} else {
    echo 
"You did not guess the secret number";
}
?>
<p>
<A>HREF="http://www.technologyforever.com">Click here to go to the TechnologyForever.com</A> 
</p>
</BODY>
</HTML>

I'm pretty sure that's for the first request, however I am attempting to do it reverse. Computer guessing the user's number.
MGT-Evelath is offline
Reply With Quote
View Public Profile
 
Old 10-18-2007, 05:12 PM Re: Creating a "Guess the Number" Game
dansgalaxy's Avatar
Defies a Status

Posts: 6,522
Name: Dan
Location: Swindon
Trades: 0
once again...

anyway...

I belive we are talking about the computer guessing the number!!

SO the USER sets the number and the computer guesses if you read the flipin thread you would know.

what i have written is much more than johns and much nearer solving how to do it. when i have time i will have to think and work on it more.

Dan
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 10-18-2007, 05:42 PM Re: Creating a "Guess the Number" Game
goheadtry's Avatar
Webmaster Talker

Posts: 726
Name: John
Location: United States of America, California
Trades: 0
Why would the computer need to guess the number if you already gave the computer the number.
That is like having your friend guess what his/her present is right after you already told them what there present is.

PHP Code:
<HTML>
<HEAD>
<TITLE>Number Game</TITLE>
</HEAD> 
<BODY>
<?php // Name this file number.php ?>
<form action="number.php" method="post">
Enter your name: <input type="text" name="number" />
<input type="submit" />
</form>
 
<?php
echo 'I guess your secret number is ';
echo 
'$_POST["number"]';
}
?>
<p>
<A>HREF="<A href="http://www.technologyforever.com">Click">http://www.technologyforever.com">Click here to go to the TechnologyForever.com</A> 
</p>
</BODY>
</HTML>
__________________
Free $1 gift card when you signup at
Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

goheadtry is offline
Reply With Quote
View Public Profile Visit goheadtry's homepage!
 
Old 10-18-2007, 05:49 PM Re: Creating a "Guess the Number" Game
MGT-Evelath's Avatar
Average Talker

Posts: 21
Trades: 0
It's basically getting the computer to guess the correct in at most 7 attempts. It has nothing to do with logic, just getting the mini-game to work correctly.
MGT-Evelath is offline
Reply With Quote
View Public Profile
 
Old 10-18-2007, 08:09 PM Re: Creating a "Guess the Number" Game
dansgalaxy's Avatar
Defies a Status

Posts: 6,522
Name: Dan
Location: Swindon
Trades: 0
Dont be thick john.

I give the computer the number the computer say stores the number in $Number but UNLIKE humans it CANT CHEAT and look!

pleas think.

You then have buttons too high too low so the computer keeps doing calcs until it gets it.
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 10-19-2007, 04:38 PM Re: Creating a "Guess the Number" Game
Inet411's Avatar
Skilled Talker

Posts: 88
Name: programmer
Location: internet
Trades: 0
Here your go:
You think of a number and the computer will guess it within 7 tries.
I wrote it without sessions and without a database. Using only get.
Obviously it could be more robust, but I just wanted to see if it was possible.

http://www.inet411.com/demos/guess.php
Inet411 is offline
Reply With Quote
View Public Profile Visit Inet411's homepage!
 
Old 10-20-2007, 04:30 AM Re: Creating a "Guess the Number" Game
MGT-Evelath's Avatar
Average Talker

Posts: 21
Trades: 0
Perfect! Could you post the php code, I am nearly complete with my own, it is actually a lot easier than I made it out to be the third time.
MGT-Evelath is offline
Reply With Quote
View Public Profile
 
Old 10-20-2007, 08:56 AM Re: Creating a "Guess the Number" Game
dansgalaxy's Avatar
Defies a Status

Posts: 6,522
Name: Dan
Location: Swindon
Trades: 0
yea please post your code!
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 10-29-2007, 10:51 PM Re: Creating a "Guess the Number" Game
MGT-Evelath's Avatar
Average Talker

Posts: 21
Trades: 0
Any updates?
MGT-Evelath is offline
Reply With Quote
View Public Profile
 
Old 05-10-2008, 12:47 AM Re: Creating a "Guess the Number" Game
Inet411's Avatar
Skilled Talker

Posts: 88
Name: programmer
Location: internet
Trades: 0
I forgot all about this thread, I'll put the code back up soon.
__________________

Please login or register to view this content. Registration is FREE

Inet411 is offline
Reply With Quote
View Public Profile Visit Inet411's homepage!
 
Reply     « Reply to Creating a "Guess the Number" Game

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.49165 seconds with 11 queries