...

View Full Version : Java Question



SniPeS
11-26-2003, 12:00 PM
I have an assignment for class, I have to create the game Hangman. It has to run in the command prompt. I have drawn scafold and created an array with words. I can randomly generate a word from that list. My first problem comes in getting the length of that word. I can't seem to figure out how to get the length of the word. When I get the length of the word i can loop the length to draw __'s for the length. My next problem would be, how do you get user inputs as guesses from the command prompt as guesses, then determine if they are in the actual word generated, then return a wrong if wrong, display correct letters in place, and add the list of guessed letters to the settings. As you can see I am pretty much a n00b so any help would be great.

Oakendin
11-26-2003, 03:35 PM
Would this help?



String word = "guess";
int lengthWord = word.length();

//For comparing
String guess = "guess";
if(word.equals(guess))
return true;

Jason
11-26-2003, 07:00 PM
you need to review the functions. Oakendin is correct with the word.length() function it will return an int and give you the length of the word. You now need to find a function similar to ElementOf so that you can see if the guess is contained in the word. Look into that...


Jason

SniPeS
11-27-2003, 12:16 AM
Thanks, I know have the length of the word and can display the correct ammount of spaced for the word. Now I am completely lost on how to get guesses and check



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum