2021-03-23 10:37:51 +01:00
|
|
|
package battleship.model;
|
|
|
|
|
2021-03-27 13:12:33 +01:00
|
|
|
import battleship.utils.*;
|
2021-03-23 10:37:51 +01:00
|
|
|
|
|
|
|
public class Ship {
|
|
|
|
|
2021-03-28 13:55:59 +02:00
|
|
|
private Pair<Integer, Integer> coords;
|
2021-03-27 13:12:33 +01:00
|
|
|
private final int size;
|
2021-03-28 14:35:10 +02:00
|
|
|
private Direction direction; // (0,-1) bas // (0,1) haut // (1,0) droite // (-1,0) gauche
|
2021-03-27 14:56:01 +01:00
|
|
|
private boolean isDrown;
|
2021-03-23 10:37:51 +01:00
|
|
|
|
2021-03-28 14:35:10 +02:00
|
|
|
public Ship(Pair<Integer, Integer> coords, int size, Direction direction) {
|
2021-03-23 10:37:51 +01:00
|
|
|
this.coords = coords;
|
|
|
|
this.size = size;
|
2021-03-27 13:12:33 +01:00
|
|
|
this.direction = direction;
|
2021-03-27 14:56:01 +01:00
|
|
|
isDrown = false;
|
2021-03-27 13:12:33 +01:00
|
|
|
}
|
2021-03-28 14:35:10 +02:00
|
|
|
public void setDirection(Direction d){
|
2021-03-28 13:55:59 +02:00
|
|
|
this.direction = d;
|
|
|
|
}
|
|
|
|
public void setCoords(Pair<Integer,Integer> c){
|
|
|
|
this.coords = c;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-03-27 14:56:01 +01:00
|
|
|
public void setDrown(){
|
|
|
|
isDrown = true;
|
2021-03-27 13:12:33 +01:00
|
|
|
}
|
2021-03-28 14:35:10 +02:00
|
|
|
|
|
|
|
public Boolean isDrown(){
|
2021-03-27 13:12:33 +01:00
|
|
|
return isDrown;
|
|
|
|
}
|
2021-03-28 14:35:10 +02:00
|
|
|
|
2021-03-27 13:12:33 +01:00
|
|
|
public int getSize(){
|
|
|
|
return this.size;
|
|
|
|
}
|
2021-03-28 14:35:10 +02:00
|
|
|
|
|
|
|
public Direction getDirection(){
|
2021-03-27 13:12:33 +01:00
|
|
|
return this.direction;
|
|
|
|
}
|
2021-03-28 14:35:10 +02:00
|
|
|
|
2021-03-27 13:12:33 +01:00
|
|
|
public Pair<Integer,Integer> getCoords(){
|
|
|
|
return this.coords;
|
2021-03-23 10:37:51 +01:00
|
|
|
}
|
2021-03-28 14:35:10 +02:00
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
2021-03-27 19:43:36 +01:00
|
|
|
public Pair<Integer, Integer>[] getCoordsArray(){
|
2021-03-28 14:35:10 +02:00
|
|
|
Pair<Integer,Integer>[] tab = new Pair[size];
|
2021-03-27 19:43:36 +01:00
|
|
|
for(int i = 0; i<size;i++){
|
|
|
|
for(int y = 0;y<size;y++){
|
2021-03-28 14:35:10 +02:00
|
|
|
tab[i] = new Pair<>(coords.getLeft()+i* direction.getDirection().getLeft(),coords.getRight()+i * direction.getDirection().getRight());
|
2021-03-27 19:43:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return tab;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2021-03-23 10:37:51 +01:00
|
|
|
|
|
|
|
}
|