I am making a game of hangman, and am wishing for the code to check if the hidden word contains any letter from the alphabet, in any position. eg charAt(0), charAt(1) etc. Once it checks if the letter is in the word, i want it to set its corresponding underlying label to that letter.
At the moment, my code is as follows:
if (SecretWord.charAt(0) == 'T') {
Underline0.setText("T");
}
if (SecretWord.charAt(1) == 't') {
Underline1.setText("t");
}
if (SecretWord.charAt(2) == 't') {
Underline2.setText("t");
}
if (SecretWord.charAt(3) == 't') {
Underline3.setText("t");
}
This does the job, but it is bulky, and it will have to be copied and pasted for all letters of the alphabet.