getPosition()

This commit is contained in:
Luca Puderbach 2024-10-10 20:30:34 +02:00
parent 0ff5fceae7
commit 91b24db6ca

View File

@ -7,14 +7,15 @@
package pp.battleship.model;
import com.jme3.network.serializing.Serializable;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import static java.lang.Math.max;
import static java.lang.Math.min;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import com.jme3.network.serializing.Serializable;
/**
* Represents a battleship in the game. A battleship is characterized by its length, position,
@ -321,4 +322,14 @@ public class Battleship implements Item {
public void accept(VoidVisitor visitor) {
visitor.visit(this);
}
public List<IntPoint> getPositions() {
List<IntPoint> positions = new ArrayList<>();
for (int x = getMinX(); x <= getMaxX(); x++) {
for (int y = getMinY(); y <= getMaxY(); y++) {
positions.add(new IntPoint(x, y));
}
}
return positions;
}
}