Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: Java Question

  1. #1
    New to the CF scene
    Join Date
    Nov 2003
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.

  • #2
    New Coder
    Join Date
    Jul 2002
    Location
    Los Angeles
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 04:53 PM.

  • #3
    Regular Coder
    Join Date
    Feb 2003
    Location
    California
    Posts
    925
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #4
    New to the CF scene
    Join Date
    Nov 2003
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •