-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPrompter.java
More file actions
30 lines (21 loc) · 994 Bytes
/
Copy pathPrompter.java
File metadata and controls
30 lines (21 loc) · 994 Bytes
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
package treehouse.hangman;
import java.util.Scanner;
//This class is responsible for getting input
public class Prompter {
private Game game;
//Make a CONSTRUCTOR to create the game
public Prompter(Game game){
this.game = game;
}
//Now we need a method to PROMPT for the guess!
public boolean promptForGuess() {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a letter: "); //this will display a line to the user to input something
String guessInput = scanner.nextLine(); //This will set "guess" equal to whatever the line is that was just entered
//we can only send ONE char to the applyGuess() ability we created, so I need to pull one char
char guess = guessInput.charAt(0);
System.out.println("This is a new line!");
//the PROMPTER doesn't test if the guess matches, that's done by the GAME logic
return game.applyGuess(guess);
}
}