guess check
Mon May 22 2023 12:41:49 GMT+0000 (Coordinated Universal Time)
Saved by
@gokulz
Scanner sc = new Scanner(System.in);
String word = randomWord();
char[] placeholder = new char[word.length()];
for(int i=0; i<placeholder.length; i++){
placeholder[i] = '_';
}
int misses = 0;
char[] missedGuess = new char[6];
while(misses<6){
System.out.println(gallows[misses]);
System.out.println("Word: ");
printPlaceHolder(placeholder);
System.out.println("\n");
System.out.println("Misses: ");
printMissesdGuess(missedGuess);
System.out.println("Guess: ");
char guess = sc.nextLine().charAt(0);
System.out.println("\n");
}
}
/**
* Function name: checkGuess
* @param word (String)
* @param guess (char)
* @return boolean
* Inside the Function
* 1. if the guess word and a word from the list are same print true
* 2. else print false.
*/
public static boolean checkGuess(String word, char guess){
for(int i=0; i<word.length(); i++){
if(word.charAt(i)==guess){
return true;
}
}
return false;
}
content_copyCOPY
Comments