-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHumanPlayer.java
More file actions
40 lines (34 loc) · 1.08 KB
/
HumanPlayer.java
File metadata and controls
40 lines (34 loc) · 1.08 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
import java.util.Scanner;
public class HumanPlayer implements Player{
private Board board;
private Scanner sc;
private char move;
public HumanPlayer(Board board, Scanner sc, char move) {
this.board = board;
this.sc = sc;
this.move = move;
}
public void playerPlays(){
int humanMoveX, humanMoveY;
while (true) {
System.out.println("Enter your x y coordinates.");
try {
humanMoveX = sc.nextInt();
humanMoveY = sc.nextInt();
if (!board.isValidMove(humanMoveX, humanMoveY)) break;
}catch(Exception e) {
System.out.println("try again.");
humanMoveX = sc.nextInt();
humanMoveY = sc.nextInt();
}
}
System.out.println("**************Your Move*************");
placeMove(humanMoveX, humanMoveY,move);
}
private void placeMove (int x, int y, char move){
if (board.isValidMove(x,y))
return;
else
board.placeMove(x, y, move);
}
}