lucasjoshua #16
|
@ -97,12 +97,7 @@ public class Ship {
|
|||
}
|
||||
|
||||
// Liste an Punkten die das Schiff einnehmen wuerde
|
||||
List<Point> shipPoints = new ArrayList<>();
|
||||
for (int i = 0; i < this.size; i++) {
|
||||
int x = horizontal ? pos.getX() + i : pos.getX(); //falls horizontal dann pos.x + i ansonsten pos.x
|
||||
int y = horizontal ? pos.getY() : pos.getY() + i;
|
||||
shipPoints.add(new Point(x, y));
|
||||
}
|
||||
List<Point> shipPoints = this.getVirtualOccupiedPoints(pos, horizontal);
|
||||
|
||||
// ueberlappen mit anderen Schiffen pruefen
|
||||
for (Ship otherShip : shipsList) {
|
||||
|
@ -126,6 +121,22 @@ public class Ship {
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Points on the ship if it were to be placed at positino `pos` in orientation defined by `horizontal`
|
||||
*/
|
||||
public List<Point> getVirtualOccupiedPoints(Point pos, boolean horizontal) {
|
||||
List<Point> points = new ArrayList<>();
|
||||
if (pos == null) {
|
||||
return points;
|
||||
}
|
||||
for (int i = 0; i < this.size; i++) {
|
||||
int x = horizontal ? pos.getX() + i : pos.getX();
|
||||
int y = horizontal ? pos.getY() : pos.getY() + i;
|
||||
points.add(new Point(x, y));
|
||||
}
|
||||
return points;
|
||||
}
|
||||
|
||||
public List<Point> getOccupiedPoints() {
|
||||
List<Point> points = new ArrayList<>();
|
||||
if (this.position == null) {
|
||||
|
|
Loading…
Reference in New Issue