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

Posts: 21
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 02:11 PM.
MGT-Evelath is offline
Reply With Quote
View Public Profile
 
Old 10-16-2007, 02:51 PM Re: Creating a "Guess the Number" Game
dansgalaxy's Avatar
Eat, Sleep, Code

Posts: 5,888
Name: Dan
Location: Swindon
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
__________________
Personal UK Webhosting
Get 25% of ANY shared package for life ~ Promo: webmaster-talk (only for members!)
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 10-16-2007, 03:38 PM Re: Creating a "Guess the Number" Game
dansgalaxy's Avatar
Eat, Sleep, Code

Posts: 5,888
Name: Dan
Location: Swindon
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
__________________
Personal UK Webhosting
Get 25% of ANY shared package for life ~ Promo: webmaster-talk (only for members!)
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 10-16-2007, 03:41 PM Re: Creating a "Guess the Number" Game
MGT-Evelath's Avatar
Average Talker

Posts: 21
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, 05:13 PM Re: Creating a "Guess the Number" Game
dansgalaxy's Avatar
Eat, Sleep, Code

Posts: 5,888
Name: Dan
Location: Swindon
ok its much harder than i thought so im gonna have to do a lot more but im tired so tomorrow....
__________________
Personal UK Webhosting
Get 25% of ANY shared package for life ~ Promo: webmaster-talk (only for members!)
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 10-17-2007, 06:13 AM Re: Creating a "Guess the Number" Game
Galaxian's Avatar
Dingleberry!

Posts: 441
Name: Rich
Location: United Kingdom
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.
Galaxian is online now
Reply With Quote
View Public Profile Visit Galaxian's homepage!
 
Old 10-17-2007, 04:35 PM Re: Creating a "Guess the Number" Game
goheadtry's Avatar
Webmaster Talker

Posts: 708
Name: John
Location: United States of America, California
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>
goheadtry is offline
Reply With Quote
View Public Profile Visit goheadtry's homepage!
 
Old 10-18-2007, 03:30 PM Re: Creating a "Guess the Number" Game
MGT-Evelath's Avatar
Average Talker

Posts: 21
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, 04:12 PM Re: Creating a "Guess the Number" Game
dansgalaxy's Avatar
Eat, Sleep, Code

Posts: 5,888
Name: Dan
Location: Swindon
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
__________________
Personal UK Webhosting
Get 25% of ANY shared package for life ~ Promo: webmaster-talk (only for members!)
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 10-18-2007, 04:42 PM Re: Creating a "Guess the Number" Game
goheadtry's Avatar
Webmaster Talker

Posts: 708
Name: John
Location: United States of America, California
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>
goheadtry is offline
Reply With Quote
View Public Profile Visit goheadtry's homepage!
 
Old 10-18-2007, 04:49 PM Re: Creating a "Guess the Number" Game
MGT-Evelath's Avatar
Average Talker

Posts: 21
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, 07:09 PM Re: Creating a "Guess the Number" Game
dansgalaxy's Avatar
Eat, Sleep, Code

Posts: 5,888
Name: Dan
Location: Swindon
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.
__________________
Personal UK Webhosting
Get 25% of ANY shared package for life ~ Promo: webmaster-talk (only for members!)
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 10-19-2007, 03:38 PM Re: Creating a "Guess the Number" Game
Inet411's Avatar
Skilled Talker

Posts: 81
Name: programmer
Location: internet
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, 03:30 AM Re: Creating a "Guess the Number" Game
MGT-Evelath's Avatar
Average Talker

Posts: 21
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, 07:56 AM Re: Creating a "Guess the Number" Game
dansgalaxy's Avatar
Eat, Sleep, Code

Posts: 5,888
Name: Dan
Location: Swindon
yea please post your code!
__________________
Personal UK Webhosting
Get 25% of ANY shared package for life ~ Promo: webmaster-talk (only for members!)
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 10-29-2007, 09:51 PM Re: Creating a "Guess the Number" Game
MGT-Evelath's Avatar
Average Talker

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

Posts: 81
Name: programmer
Location: internet
I forgot all about this thread, I'll put the code back up soon.
Inet411 is offline
Reply With Quote
View Public Profile Visit Inet411's homepage!
 
Reply     « Reply to Creating a "Guess the Number" Game