How can I keep track of the unguessed letters yet in my JTextArea? In the non gui version I used an arraylist, worked fine but should I leave the arraylist and use it to track unguessed caracters ? The method is still console based, just started implementing the gui made the layout now connecting it. What I did so far was append the number of letters that the chosen word contains
public void guessWord(){
for (int i = 0; i<wordToGuess.length();i++){ //create all letters represented by "_"
al.add(i," _ ");
}
//System.out.println(al);
for(String s: al){
wordToGuessGUI.append(s);
}
Scanner sc = new Scanner(System.in);
while(wrongGuesses<5 && al.contains(" _ ")){ // If 5 mistakes or the word is completed
letter = sc.next(); //get input
if(wordToGuess.contains(letter)){ //does the word contain the input letter
guessedLetter = wordToGuess.indexOf(letter); //location of the guessed letter
al.set(guessedLetter,letter); //replace the "_" with the letter guessed
System.out.println(al); //print the current state of the word
if(!al.contains(" _ ")) System.out.println("Congratulations, you won!");
}
else {
System.out.println("Wrong, try again! " +wrongGuesses +" out of 5 wrong attempts");
wrongGuesses++;
if(wrongGuesses>=5) System.out.println("Game Lost"); // game lost if 5 incorrect answers
}
}}