From ad61fcecb7b9ccbc38bdb9f788d7809bcbc04344 Mon Sep 17 00:00:00 2001 From: Kaver Date: Sun, 15 Dec 2024 15:51:32 +0100 Subject: [PATCH] Anpasung an paintFields, sodass preview unterscheidet, ob setzen von Schiff valide ist --- src/BoardDisplay.java | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/src/BoardDisplay.java b/src/BoardDisplay.java index ca2e327..1bb501e 100644 --- a/src/BoardDisplay.java +++ b/src/BoardDisplay.java @@ -110,11 +110,19 @@ public class BoardDisplay extends JPanel { } + /** + * Aktuelles Schiff auswaehlen + * @param ship + */ public void selectCurrentShip(Ship ship) { this.currentShip = ship; paintFields(); } + /** + * Zuruecksetzen von aktuellem Schiff und allen Schiffen des Spielers + * Danach blau faerben des Spielfeldes + */ public void resetAllShips() { //ships.clear(); this.currentShip = null; @@ -123,22 +131,6 @@ public class BoardDisplay extends JPanel { } paintFields(); } - /** - * TODO Funktion beschreiben etc. - * @param ship - * @param o - * @param horizontal - * @param player - * @return - */ - - /** - * TODO Funktion beschreiben etc. - * @param ship - * @param o - * @param horizontal - * @return - */ /** * Wechselt die Platzierungsrichtung zwischen horizontal und vertikal. @@ -179,8 +171,10 @@ public class BoardDisplay extends JPanel { } fields[i][j].setBackground(Color.BLUE); for(Point p : test) { - if(i==p.getX() && j==p.getY()) { - fields[i][j].setBackground(Color.YELLOW); + if(i==p.getX() && j==p.getY() && currentShip.checkValidPlacement(mousePosition,horizontal,player.getBoard().getShips(),gridSize)) { + fields[i][j].setBackground(Color.GREEN); + }else if(i==p.getX() && j==p.getY() && !currentShip.checkValidPlacement(mousePosition,horizontal,player.getBoard().getShips(),gridSize)) { + fields[i][j].setBackground(Color.RED); } } for(Ship ship: player.getBoard().getShips()) {