hey guys new on here but im in second year studying game development and we have a simple exercise to do involving a hangman game and for some reason i can't seem to get my head around the idea of double letter like "pool" has two "o" but i can only ever print out the first ? there's what i have done so far any insights would be much appreciated!!
import java.util.Scanner;
import java.util.Random;
public class Excersize09_25 {
public static void main(String[] args) {
Random rand = new Random();
Scanner input = new Scanner(System.in);
String[] words= {"tiger","elephant","monster","school","cage","poo l","killer"};
int n = rand.nextInt(6);
String secretWord = words[n];
String hiddenWord = secretWord.replaceAll(".","*" );
System.out.print("Okay a word has been choosen " + "\n");
boolean gameOver =false;
while(gameOver!=true){
System.out.print("(guess) Enter a letter in the word " );
System.out.println(hiddenWord + " >");
char guess=input.nextLine().charAt(0);
for(int i=0 ; i<secretWord.length();i++){
int position = secretWord.indexOf(guess);
String newDisplaySecret = "";
for (int k = 0; k < secretWord.length(); k++)
if (k == position)
newDisplaySecret += secretWord.charAt(k);
else
newDisplaySecret += hiddenWord.charAt(k);
hiddenWord = new String(newDisplaySecret);
}
if(hiddenWord.compareTo(secretWord)==0){
System.out.print("well done you guessed the word " + secretWord);
gameOver=true;
}
}
}
}