I need some hints on how to program this, this method is for a hangman game guessCh is the letter user has guessed while secretCh is the letters in the secret word, they come from a while() loop one at a time. But what I need is instead of just if (guessCh != secretCh) wich don´t work cause the secret word consist of severall letters so it will subtract points from all those letters within the secret word, that it should not subtract from. Only if the guessCh char is not found in any of the secretCh letters / or within the secret word should it subtract -1.
I seem to be stuck on this, I know it´s simple… but throw me a bone. I´ve already spent to much time on this.
private void nTurns(char guessCh, char secretCh) {
//Create an array that stores already used letters
if (guessCh != secretCh) {
nTurnsLeft--;
}
}
The String object already has this functionality built in.
All you really need is something like this:
indexOf returns the index of the location of the char guessCh inside the String secretStr. If guessCh is not found, then indexOf returns -1;