-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.java
67 lines (61 loc) · 1.73 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
57
58
59
60
61
62
63
64
65
66
67
public class Player {
private Grid gridJoueur = new Grid();
private Grid gridAdv = new Grid();
private String name;
int shipStillAliveJoueur = 0;
int shipStillAliveAdv = 0 ;
public boolean addShip(Ship ship, int rowIndex, int columnIndex, Orientation orientation) {
boolean res;
if( orientation.isHorizontal() )
{
if(columnIndex + ship.getSize()< 10 && rowIndex <10)
{
gridJoueur = ship.addToGrid(gridJoueur, rowIndex, columnIndex, orientation);
shipStillAliveJoueur++;
res = true;
}
else
{
res = false;
}
}
else
{
if(rowIndex + ship.getSize()< 10 && columnIndex <10)
{
gridJoueur = ship.addToGrid(gridJoueur, rowIndex, columnIndex, orientation);
res = true;
}
else
{
res = false;
}
}
return res;
}
public HitResult hit(int rowIndex, int columnIndex){
HitResult res = this.gridAdv.getCell(rowIndex,columnIndex).hit();
if (res instanceof ShipHit)
{
if (((ShipHit)res).getShipRemainingCellCount() == 0 )
{
shipStillAliveJoueur--;
}
}
return res;
}
public Grid getGridJoueur() {
return this.gridJoueur ;
}
public Grid getGridAdv() {
return this.gridAdv ;
}
public boolean isDestroyed(){
boolean res = false;
if(shipStillAliveJoueur == 0)
{
res = true;
}
return res;
}
}