-
Notifications
You must be signed in to change notification settings - Fork 0
/
HumanPlayer.java
47 lines (34 loc) · 1.16 KB
/
HumanPlayer.java
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
46
47
//import packages that allow the user to input into the command line.
import java.io.BufferedReader;
import java.io.InputStreamReader;
//HumanPlayer is a subclass of Player.
public class HumanPlayer extends Player{
//declare the user's input in this class
private BufferedReader input;
public HumanPlayer(char token){
//inherits all objects from Player class
super(token);
//initialise the input
input = new BufferedReader(new InputStreamReader(System.in));
}
//accessor to get the user's input
public String getUserInput() {
//default is nothing
String toReturn = null;
try {
//take the user's input from the command line
toReturn = input.readLine();
} catch (Exception e) {
}
//return toReturn if it's okay.
return toReturn;
}
//accessor to retrieve the user's position in which they placed their counter. Allows for code reuse.
public int getMove(){
//the user inputs a string
String userInput = getUserInput();
//and Java turns it into an integer!
int move = Integer.parseInt(userInput);
return move;
}
}