Index Check and Correct Character Display in a Console Hangman Game for Java

Posted by Jen on Game Development See other posts from Game Development or by Jen
Published on 2012-11-27T14:00:45Z Indexed on 2012/11/27 17:22 UTC
Read the original article Hit count: 221

Filed under:

I have this problem wherein, I can not display the correct characters given by the character. Here's what I meant:

String words, in;
    String replaced_words;

    Scanner s = new Scanner (System.in);

        System.out.println("Enter a line of words basing on an event, verse, place or a name of a person.");
        words = s.nextLine();
        System.out.println("The words you just placed are now accepted.");
        //using char array method, we tried to place the words into a characters array.
        char [] c = words.toCharArray();
        // we need to replace the 
        replaced_words = words.replace(' ', '_').replaceAll("[^\\-]", "-");
        for (int i = 0; i < replaced_words.length(); i++) {
            System.out.print(replaced_words.charAt(i) + " ");
        }
        System.out.println("Now, please input a character, guessing the words you just placed.");
        in = s.nextLine();

in that code, want that the user, when types a word (or should it be character?), any of the correct character the user inputs will be displayed, and changes the hyphen to it...(more like the hangman series of games).

How can I achieve this?

© Game Development or respective owner

Related posts about java