This is my first question on this site so i\'ll try not to be a total noob..
I\'m currently creating hangman game in java. So my question to you is if we are given a wor
Why not have another array of true/false values that mark what letters have been guessed and what letters are still unknown? I don't think using regex and string replaces is an easy way to go about getting hangman to work, especially when they guess another letter.
Something like this perhaps.
String answer = "someword";
boolean[] knownLetters = new boolean[answer.length()];
for (int i = 0; i < answer.length(); i++) {
if(knownLetters[i]) {
System.out.print(answer.charAt(i));
} else {
System.out.print("_");
}
}
System.out.println("");