Browse Source

fixed the letter checking function

underscores aren't showing up
master
school 7 years ago
parent
commit
c83a3b5ad6
  1. 19
      Hangman.java

19
Hangman.java

@ -41,12 +41,16 @@ public class Hangman extends Application {
scene.setRoot(newPane);
});
scene.setOnKeyPressed(
e -> {
//System.out.println("Key pressed!!");
if (activeGame) {
String guess = e.getText();
//System.out.println(guess);
guess = guess.toLowerCase();//use a string method to convert guess to lowercase
checkGuess(guess, statusBox);
}
});
@ -60,7 +64,7 @@ public class Hangman extends Application {
//set new word to guess
this.secretWord = dict.getRandomWord();
System.out.println(this.secretWord);
GridPane word = new GridPane();
word.setHgap(5);
@ -74,7 +78,7 @@ public class Hangman extends Application {
//create letterGuesses
this.letterGuesses = new Text[26];// finish this line
for (int i = 0; i < 26; i++) {
String temp = "_";//finish this line
String temp = String.valueOf(Dictionary.ALPHABET.charAt(i));//finish this line
this.letterGuesses[i] = new Text(temp);
letterGuesses[i].setFont(gameFont);
lettersPane.add(letterGuesses[i], i % 13, i / 13);
@ -152,8 +156,13 @@ public class Hangman extends Application {
}
}
private int findLetter(String s) {
int index = Dictionary.ALPHABET.indexOf(s);
boolean isLetter = (index != -1) && (s.length() == 1);
if (s.length() == 1) {
return Dictionary.ALPHABET.indexOf(s);
}
else {
return -1;
}
/*boolean isLetter = (index != -1) && (s.length() == 1);
//Determine if s contains a single letter of the alphabet, using String methods
//Return the index of this letter in the array letterGuesses
//e.g. "a" is stored in index 0, "b" in index 1, etc.
@ -167,7 +176,7 @@ public class Hangman extends Application {
}
}
}
return ret;
return ret;*/
//write your code for this method
}
private boolean alreadyGuessed(int index) {

Loading…
Cancel
Save