lucasjoshua #16

Merged
lgc merged 8 commits from lucasjoshua into main 2024-12-15 15:02:32 +00:00
1 changed files with 17 additions and 6 deletions
Showing only changes of commit 60e44f2e1a - Show all commits

View File

@ -97,12 +97,7 @@ public class Ship {
} }
// Liste an Punkten die das Schiff einnehmen wuerde // Liste an Punkten die das Schiff einnehmen wuerde
List<Point> shipPoints = new ArrayList<>(); List<Point> shipPoints = this.getVirtualOccupiedPoints(pos, horizontal);
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));
}
// ueberlappen mit anderen Schiffen pruefen // ueberlappen mit anderen Schiffen pruefen
for (Ship otherShip : shipsList) { for (Ship otherShip : shipsList) {
@ -126,6 +121,22 @@ public class Ship {
return true; 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() { public List<Point> getOccupiedPoints() {
List<Point> points = new ArrayList<>(); List<Point> points = new ArrayList<>();
if (this.position == null) { if (this.position == null) {