I'm trying to implement a hangman game using linked lists but not getting anywhere. I want guessed characters to be inserted in a Linked list of chars at a position that corresponds to the character's position in the word they are trying to guess.(See example at bottom.) For some reason my play() method doesn't do what it's supposed to do.

  1. I have a gameLinkedList class that takes in a word; creates a charNode reference (character node) and a LinkedList of charNodes with their info set to the '_' character. the size of the linked list is equal to the size of the word.

  2. I have a play method that takes in a character and determines whether the character exists in the word. If it does, then the play method is supposed to replace the '_' in the charNode linked list that corresponds to the position of that char in the word.

  3. For example, a word like drone would result in a newNode linked list of _ _ _ _ _ If a gameLinkedList object gll is created and it calls play('o') i.e. gll.play('o') This would change the newNode to _ _ o _ _

    Here's how my class looks like

    public class gameLinkedList{
    private charNode game;
    private String newString;
    private int size;
    public gameLiknedList(String word){
    for(int i=0;i<size;i++){charNode newNode = new charNode('_');
     public boolean charExists(guess){return newString.indexOf(guess)>0;}    
     public boolean play(guess){charNode kNode=game;
       for(int j=0;j==newString.indexOf(guess);j++){
    Any help is appreciated

The loop on line 17 looks suspicious. Why not loop all the way down the list?
Line 15; what's the initial value of game?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.