-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrompter.java
More file actions
45 lines (38 loc) · 1.15 KB
/
Prompter.java
File metadata and controls
45 lines (38 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import java.util.Scanner;
public class Prompter {
private Game game;
public Prompter(Game game) {
this.game = game;
}
public boolean promptForGuess() {
Scanner scanner = new Scanner(System.in);
boolean isHit = false;
boolean isAcceptable = false;
do {
System.out.print("Enter a letter: ");
String guessInput = scanner.nextLine();
try {
isHit = game.applyGuess(guessInput);
isAcceptable = true;
} catch(IllegalArgumentException iae) {
System.out.printf("%s. Please try again. %n",
iae.getMessage());
}
} while (! isAcceptable);
return isHit;
}
public void displayProgress() {
System.out.printf("You have %d tries left to solve: %s%n",
game.getRemainingTries(),
game.getCurrentProgress());
}
public void displayOutcome() {
if (game.isWon()) {
System.out.printf("Congrations, you won with %d tries remaining.%n",
game.getRemainingTries());
} else {
System.out.printf("Bummer the word was %s. :( %n",
game.getAnswer());
}
}
}