Anpasung an paintFields, sodass preview unterscheidet, ob setzen von Schiff valide ist
This commit is contained in:
parent
b4f1de82bd
commit
ad61fcecb7
|
@ -110,11 +110,19 @@ public class BoardDisplay extends JPanel {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Aktuelles Schiff auswaehlen
|
||||||
|
* @param ship
|
||||||
|
*/
|
||||||
public void selectCurrentShip(Ship ship) {
|
public void selectCurrentShip(Ship ship) {
|
||||||
this.currentShip = ship;
|
this.currentShip = ship;
|
||||||
paintFields();
|
paintFields();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Zuruecksetzen von aktuellem Schiff und allen Schiffen des Spielers
|
||||||
|
* Danach blau faerben des Spielfeldes
|
||||||
|
*/
|
||||||
public void resetAllShips() {
|
public void resetAllShips() {
|
||||||
//ships.clear();
|
//ships.clear();
|
||||||
this.currentShip = null;
|
this.currentShip = null;
|
||||||
|
@ -123,22 +131,6 @@ public class BoardDisplay extends JPanel {
|
||||||
}
|
}
|
||||||
paintFields();
|
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.
|
* Wechselt die Platzierungsrichtung zwischen horizontal und vertikal.
|
||||||
|
@ -179,8 +171,10 @@ public class BoardDisplay extends JPanel {
|
||||||
}
|
}
|
||||||
fields[i][j].setBackground(Color.BLUE);
|
fields[i][j].setBackground(Color.BLUE);
|
||||||
for(Point p : test) {
|
for(Point p : test) {
|
||||||
if(i==p.getX() && j==p.getY()) {
|
if(i==p.getX() && j==p.getY() && currentShip.checkValidPlacement(mousePosition,horizontal,player.getBoard().getShips(),gridSize)) {
|
||||||
fields[i][j].setBackground(Color.YELLOW);
|
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()) {
|
for(Ship ship: player.getBoard().getShips()) {
|
||||||
|
|
Loading…
Reference in New Issue