Welcome to Dream.In.Code
Getting Help is Easy!

Join 132,613 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 926 people online right now. Registration is fast and FREE... Join Now!




Creating a guess game

 
Reply to this topicStart new topic

Creating a guess game

Complearn
post 2 Jul, 2008 - 07:40 PM
Post #1


New D.I.C Head

*
Joined: 2 Jul, 2008
Posts: 1

Hi, Iīm a computerīs programming student. Iīm glad about finding this site. Iīm thrying to build a game wit the following conditions:

Computer should pick a random number between 1 and 100, inclusive.
Player inputs their guess
Program should respond "too high", "too low" or "correct"
If the guess is "too high" or "too low" the game should continue (player makes next guess.)
If the guess is correct, the game should end, and the player should be told how many guesses it took to win.
Include a "new game" button that allows a new game to begin if the user clicks it. (You should pick a new random number, and reset the number of guesses.)

I have the following code, but it is not working and I donīt know why. This code for an action script 3.0 program. Iīm also attaching a list of mistakes that I donīt know how to solve since Iīm very new in this field. I hope somebody can help me in fixing this.

CODE

var msg:String = "Enter a number between 1 and 100";
var theNumber:Number = Math.floor(Math.random()*100+1);
var totalGuesses:Number = 0;
var theGuess:Number;
display.text = msg;
guesses.text = totalGuesses = 0;
/*Create a function to check the guessed number against the random numberThe function will run each time the user clicks on the Enter button
*/
rollbtn.onRelease = function() {
/* Extract the guess from the input box */
theGuess = Number(guess.text);
/* Add 1 to the total number of guesses */
totalGuesses++;
/* Display the total number of guesses */
guesses.text = totalGuesses;
/*
Check to to see if the guess equals the random number
IF it does THEN
pick a new random number
reset the total number of guesses to zero
clear the input box
prompt the player to play again
ELSE
Provide the player with feedback
*/
if (theGuess == theNumber) {
display.text = "You Got It! \n Play Again";
theNumber = Math.floor(Math.random()*100+1);
totalGuesses = 0;
guess.text = "";
} else if (theGuess > theNumber) {
display.text = "Too High";
} else if (theGuess < theNumber) {
display.text = "Too Low";
} else {
display.text = "Not a Number\nTry again";
}
};


Thanks for your help

** Edit ** code.gif
User is offlineProfile CardPM

Go to the top of the page

Tom9729
post 2 Jul, 2008 - 08:49 PM
Post #2


Debian guru

Group Icon
Joined: 30 Dec, 2007
Posts: 1,447



Thanked 10 times

Dream Kudos: 325
My Contributions


Please post inside code tags, like this code.gif. smile.gif
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 02:44AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month