Skip to content

Commit ce52ea9

Browse files
author
Dorian
committed
feat: Função geral de Entrada
1 parent 3db701c commit ce52ea9

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

src/LetterDealer.java

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,35 @@ void guessLetter(String gameWord, int wordNumLetters, String hiddenWord) {
1111
char[] chHidden = hiddenWord.toCharArray();
1212

1313
List<String> wrongLetters = new ArrayList<>();
14-
15-
int rightLetters = 0;
14+
int rightLetters = 0;
1615
int numTrys = 7;
16+
char letter;
1717

18-
while (true) {
1918

19+
while (true) {
20+
2021
boolean letterWasRight = false;
21-
char letter;
22+
23+
try{
2224

2325
System.out.println("Chute uma letra: ");
2426
letter = scan.nextLine().toLowerCase().charAt(0);
2527

28+
if(!checkInput(letter)){
29+
System.out.println("So aceitamos letras (a-Z)");
30+
continue;
31+
}
32+
33+
}
34+
catch(StringIndexOutOfBoundsException e){
35+
System.out.println("Entrada Invalida. Digite uma letra (a-A)");
36+
continue;
37+
}
38+
catch(Exception e){
39+
System.out.println("ERRO INESPERADO");
40+
continue;
41+
}
42+
2643
for (int i = 0; i < ch.length; i++) {
2744

2845
//Prevents counting the same correct letter twice
@@ -64,4 +81,8 @@ void guessLetter(String gameWord, int wordNumLetters, String hiddenWord) {
6481

6582
}
6683
}
84+
private static boolean checkInput(char letter){
85+
return Character.isLetter(letter);
86+
}
87+
6788
}

0 commit comments

Comments
 (0)