-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHumanPlayer.java
More file actions
53 lines (38 loc) · 1.33 KB
/
HumanPlayer.java
File metadata and controls
53 lines (38 loc) · 1.33 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
41
42
43
44
45
46
47
48
49
50
51
52
53
import java.util.ArrayList;
import java.util.Scanner;
class HumanPlayer extends Player {
public HumanPlayer(String name, char symbol) {
super(name, symbol);
}
public void play(XandOGame game){
Scanner keyboard = new Scanner(System.in);
// call the checkAvailableCells method to check for available methods
ArrayList<Integer> availableCells = game.getAvailableCells();
//choose a random cells and pass it to the modify game State method
for (int i = 0; i < availableCells.size(); i++){
System.out.print(availableCells.get(i) + ", ");
}
System.out.println();
int choosenCell = 0;
while(availableCells.size() > 0 ){
System.out.println(getName() + ": " + getSymbol() + ", These are the available cells... please choose one");
if(keyboard.hasNextInt()){
//keyboard.nextLine();
choosenCell = keyboard.nextInt();
}
while(!availableCells.contains(choosenCell)){
System.out.println("the cell you've choosen isn't available, please choose another one ");
if(keyboard.hasNextInt()){
//keyboard.nextLine();
choosenCell = keyboard.nextInt();
}
break;
}
break;
}
int symbolValue = resolveSymbol();
game.modifyGameState(choosenCell, symbolValue);
System.out.println(getSymbol() + " just played...");
game.printGameBoard();
}
}