-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.java
56 lines (47 loc) · 1.2 KB
/
Player.java
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
54
55
56
import java.io.File;
import java.io.FileNotFoundException;
public class Player {
private BattleshipBoard board;
private boolean turn;
protected boolean spacesHit[][];
public Player(File boardFile) throws FileNotFoundException{
board = new BattleshipBoard(boardFile);
this.turn = false;
spacesHit = new boolean[10][10];
for(int c = 0; c < 10; c++)
for(int i = 0; i < 10; i++)
spacesHit[c][i] = false;
}
public Player(int cols, int rows) throws BattleshipException{
board = new BattleshipBoard(cols, rows);
this.turn = false;
spacesHit = new boolean[10][10];
for(int c = 0; c < 10; c++)
for(int i = 0; i < 10; i++)
spacesHit[c][i] = false;
}
public BattleshipBoard getBoard(){
return this.board;
}
public boolean takeTurn(BattleshipBoard oppBoard, int col, int row)
{
spacesHit[col][row] = true;
this.turn = false;
return oppBoard.fireShot(col, row);
}
public void setTurn(boolean turn){
this.turn = turn;
}
public boolean getTurn(){
return this.turn;
}
public boolean checkLost(){
return this.board.isGameOver();
}
public boolean checkPlayerHitSquareTwice(int col, int row){
if(spacesHit[col][row])
return true;
else
return false;
}
}