I have created a hangman-game.
I want to ask how I can check if the user type the same letter. Everything is working fine but without checking if the number is allready typed.
if (word.contains(input)) {
i = i - 1;
char[] charOfGameBoard = gameBoard.toCharArray();
for (int x = 0; x < word.length(); x++) {
if (word.charAt(x) != input.charAt(0)) {
continue;
}
int j = x * 2;
charOfGameBoard[j] = input.charAt(0);
}
gameBoard = String.valueOf(charOfGameBoard);
}
I cant post to much sry.
word = "house"
charOfGameBoard= _ _ _ _ _
userinput= "h" //Correct
charOfGameBoard =h _ _ _ _
userinput= "h" // incorrect at this point
charOfGameBoard =h _ _ _ _
Aucun commentaire:
Enregistrer un commentaire