Button ausschalten wenn Schiff gesetzt wurde, nicht komplett richtige Funktion
This commit is contained in:
parent
88ec23c5e5
commit
a7e7d75c62
|
@ -154,12 +154,16 @@ public class BoardDisplay extends JPanel {
|
|||
if (!this.currentShip.setPosition(o,player.getBoard().getShips(),this.gridSize)) {
|
||||
}
|
||||
paintFields();
|
||||
//if(this.currentShip.isPlaced()){
|
||||
// this.currentShip.
|
||||
// };
|
||||
// Beispiel: Setze ein Schiff bei einem Klick
|
||||
//if (setShip(new Ship(3, "TestShip"), o, true,player)) {
|
||||
// field.setBackground(Color.BLUE); // Visualisiere Schiff
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
public void paintFields() {
|
||||
for(int i = 0; i < gridSize; i++) {
|
||||
for(int j = 0; j < gridSize; j++) {
|
||||
|
|
|
@ -84,18 +84,27 @@ public class GameBoard extends JPanel {
|
|||
JPanel rightButtonsPanel = new JPanel();
|
||||
rightButtonsPanel.setLayout(new GridLayout(7, 1));
|
||||
|
||||
//Buttons in eine Gruppe packen damit diese beim drücken eines anderen Buttons wieder entwählt werden
|
||||
ButtonGroup leftButtonGroup= new ButtonGroup();
|
||||
|
||||
ButtonGroup rightButtonGroup= new ButtonGroup();
|
||||
|
||||
// Panel für die Buttons des linken Spielers (ganz links)
|
||||
for(Ship ship : p1.getBoard().getShips()) {
|
||||
ShipButton shipButton= new ShipButton(ship,ownBoardPanel);
|
||||
leftButtonsPanel.add(shipButton);
|
||||
leftButtonGroup.add(shipButton);
|
||||
}
|
||||
|
||||
for(Ship ship : p2.getBoard().getShips()) {
|
||||
ShipButton shipButton= new ShipButton(ship,ownBoardPanel);
|
||||
ShipButton shipButton= new ShipButton(ship,opponentBoardPanel);
|
||||
rightButtonsPanel.add(shipButton);
|
||||
rightButtonGroup.add(shipButton);
|
||||
}
|
||||
|
||||
JToggleButton rightPlayerModul7 = new JToggleButton("Bereit");
|
||||
rightButtonsPanel.add(rightPlayerModul7);
|
||||
|
||||
JToggleButton leftPlayerModul7 = new JToggleButton("Reset");
|
||||
leftButtonsPanel.add(leftPlayerModul7);
|
||||
// Panel für die Buttons des rechten Spielers (ganz rechts)
|
||||
|
@ -103,11 +112,6 @@ public class GameBoard extends JPanel {
|
|||
//JPanel ownBoardPanel = new JPanel(new GridLayout(gridSize, gridSize));
|
||||
//JPanel opponentBoardPanel = new JPanel(new GridLayout(gridSize, gridSize));
|
||||
|
||||
//Buttons in eine Gruppe packen damit diese beim drücken eines anderen Buttons wieder entwählt werden
|
||||
ButtonGroup leftButtonGroup= new ButtonGroup();
|
||||
|
||||
ButtonGroup rightButtonGroup= new ButtonGroup();
|
||||
|
||||
// Panel für beide Spielfelder (nebeneinander in der Mitte)
|
||||
JPanel centerPanel = new JPanel();
|
||||
centerPanel.setLayout(new GridLayout(1, 2, 20, 0)); // 2 Spielfelder nebeneinander, mit Abstand von 20 Pixeln
|
||||
|
|
|
@ -51,6 +51,7 @@ public class Ship {
|
|||
private String name;
|
||||
private int hitsOnMe;
|
||||
private boolean sunk;
|
||||
private boolean isPlaced;
|
||||
|
||||
public Ship (int size, String name) {
|
||||
this.size = size;
|
||||
|
@ -59,6 +60,7 @@ public class Ship {
|
|||
this.position = null;
|
||||
this.hitsOnMe = 0;
|
||||
this.sunk = false;
|
||||
this.isPlaced = false;
|
||||
}
|
||||
|
||||
public boolean setPosition(Point pos, List<Ship> shipsList, int boardSize) {
|
||||
|
@ -172,4 +174,9 @@ public class Ship {
|
|||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
//potentiell falsch neu
|
||||
public boolean isPlaced(){
|
||||
return this.position != null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,12 @@ public class ShipButton extends JButton {
|
|||
this.ship = ship;
|
||||
this.addActionListener((e)->{
|
||||
boardDisplay.selectCurrentShip(this.ship);
|
||||
this.setEnabled(false);
|
||||
});
|
||||
}
|
||||
|
||||
public void buttonPressed() {
|
||||
this.setEnabled(!ship.isPlaced());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue