Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-26-2003, 12:00 PM   PM User | #1
SniPeS
New to the CF scene

 
Join Date: Nov 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
SniPeS is an unknown quantity at this point
Java Question

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.
SniPeS is offline   Reply With Quote
Old 11-26-2003, 03:35 PM   PM User | #2
Oakendin
New Coder

 
Join Date: Jul 2002
Location: Los Angeles
Posts: 89
Thanks: 0
Thanked 0 Times in 0 Posts
Oakendin is an unknown quantity at this point
Would this help?

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

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

Last edited by Oakendin; 11-26-2003 at 03:53 PM..
Oakendin is offline   Reply With Quote
Old 11-26-2003, 07:00 PM   PM User | #3
Jason
Regular Coder

 
Join Date: Feb 2003
Location: California
Posts: 925
Thanks: 0
Thanked 0 Times in 0 Posts
Jason is an unknown quantity at this point
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
Jason is offline   Reply With Quote
Old 11-27-2003, 12:16 AM   PM User | #4
SniPeS
New to the CF scene

 
Join Date: Nov 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
SniPeS is an unknown quantity at this point
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
SniPeS is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 05:48 PM.


Advertisement
Log in to turn off these ads.