-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathHumanPlayer.java
More file actions
38 lines (33 loc) · 1.01 KB
/
HumanPlayer.java
File metadata and controls
38 lines (33 loc) · 1.01 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
package ticTacToe;
import java.io.PrintStream;
import java.util.Scanner;
/**
* @author Georgiy Korneev (kgeorgiy@kgeorgiy.info)
*/
public class HumanPlayer implements Player {
private final PrintStream out;
private final Scanner in;
public HumanPlayer(final PrintStream out, final Scanner in) {
this.out = out;
this.in = in;
}
public HumanPlayer() {
this(System.out, new Scanner(System.in));
}
@Override
public Move move(final Position position, final Cell cell) {
// Board bruh = (Board) position;
while (true) {
out.println("Position");
out.println(position);
out.println(cell + "'s move");
out.println("Enter row and column");
int[] input = UserInput.get(2, in);
final Move move = new Move(input[0], input[1], cell);
if (position.isValid(move)) {
return move;
}
out.println("Move " + move + " is invalid");
}
}
}