Reset Button Funktionalität hinzugefuegt

This commit is contained in:
Kaver 2024-12-14 16:47:12 +01:00
parent decef526da
commit 587d88f764
2 changed files with 16 additions and 0 deletions

View File

@ -92,6 +92,15 @@ public class BoardDisplay extends JPanel {
this.currentShip = ship;
}
public void resetAllShips() {
ships.clear();
this.currentShip = null;
for(int i = 0; i < gridSize; i++) {
for(int j = 0; j < gridSize; j++) {
fields[i][j].setBackground(Color.BLUE);
}
}
}
/**
* TODO Funktion beschreiben etc.
* @param ship

View File

@ -136,6 +136,13 @@ public class GameBoard extends JPanel {
JToggleButton leftPlayerModul7 = new JToggleButton("Reset");
leftPlayerModul7.setBackground(Color.RED);
leftButtonsPanel.add(leftPlayerModul7);
leftPlayerModul7.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ownBoardPanel.resetAllShips();
}
});
// Panel für die Buttons des rechten Spielers (ganz rechts)
//JPanel ownBoardPanel = new JPanel(new GridLayout(gridSize, gridSize));