-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.java
More file actions
46 lines (36 loc) · 1.21 KB
/
Player.java
File metadata and controls
46 lines (36 loc) · 1.21 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
abstract class Player {
private Board board;
private String[] playerName;
private int playerIndex;
public Player(Board board, String[] playerName, int playerIndex) {
this.board = board;
this.playerName = playerName;
this.playerIndex = playerIndex;
}
public abstract int getPositionNum();
public String getPlayerName() {
return playerName[playerIndex];
}
public boolean isOutOfBoard(int position) {
boolean isFullPosition = board.isFullColumn(position);
if (isFullPosition && playerIndex == 0) {
PrintHelper.showErrorUnabledPut();
}
return isFullPosition;
}
public void putPosition(Player player) {
PrintHelper.showTurnMsg(getPlayerName());
boolean isNotFullColumn = true;
// MEMO: check non-exsisting board position number at first
int position = 9999;
while (isNotFullColumn) {
position = player.getPositionNum();
isNotFullColumn = isOutOfBoard(position);
}
board.placeCounter(playerIndex, position);
board.printBoard();
}
public boolean hasWinPosition() {
return board.checkNPlacement(playerIndex);
}
}