From 91b24db6ca2d347e9a05062340aaaeaba32be001 Mon Sep 17 00:00:00 2001 From: Luca Puderbach Date: Thu, 10 Oct 2024 20:30:34 +0200 Subject: [PATCH] getPosition() --- .../java/pp/battleship/model/Battleship.java | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/Projekte/battleship/model/src/main/java/pp/battleship/model/Battleship.java b/Projekte/battleship/model/src/main/java/pp/battleship/model/Battleship.java index 7b9e583..4bea42e 100644 --- a/Projekte/battleship/model/src/main/java/pp/battleship/model/Battleship.java +++ b/Projekte/battleship/model/src/main/java/pp/battleship/model/Battleship.java @@ -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 getPositions() { + List 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; +} + }