-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHumanPlayer.java
More file actions
27 lines (25 loc) · 781 Bytes
/
HumanPlayer.java
File metadata and controls
27 lines (25 loc) · 781 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
import java.util.*;
public class HumanPlayer extends Player{
public HumanPlayer(String theName, int thePlayerNum){
super(theName, thePlayerNum);
}
public int playChip(GameBoard board){
Scanner sc = new Scanner(System.in);
String validCols = board.getValidColumns();
boolean badCol = false;
int passedCol = -1;
while(!badCol){
badCol = true;
System.out.println(name + "'s turn");
System.out.println("What column do you want to play a chip?\nValid cols are " + validCols);
passedCol = sc.nextInt();
sc.nextLine();
String passed = "" + passedCol;
if(validCols.indexOf(passed) == -1){
System.out.println("Please enter a valid column");
badCol = false;
}
}
return passedCol;
}
}