Added more Javadoc (TODOs) comments.

Added new sound.
temporarily disabled sound when hitting/sinking ships (buggy)
This commit is contained in:
Joshua 2024-12-17 15:58:05 +01:00
parent db2b0532bc
commit 1f04760f6a
4 changed files with 17 additions and 17 deletions

BIN
Sound/loosescreenWAH.mp3 Normal file

Binary file not shown.

View File

@ -6,8 +6,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
* TODO Klassenbeschreibung * Dient dem Aufbau der Matrix (Spielfeld) und füllt diese mit Funktion
* reines im frontend zeichnen für preview
*/ */
public class BoardDisplay extends JPanel { public class BoardDisplay extends JPanel {
private JButton[][] fields; private JButton[][] fields;
@ -18,10 +17,9 @@ public class BoardDisplay extends JPanel {
private List<ShipButton> shipButtonList; private List<ShipButton> shipButtonList;
private boolean enemyBoard; private boolean enemyBoard;
private Point mousePosition; private Point mousePosition;
private boolean shipsplaced;
/** /**
* TODO Funktion beschreiben * Fügt Buttons zu Liste hinzu und aktualisiert Feld durch Aufruf von paintFields
* @param button * @param button
*/ */
public void addShipButton(ShipButton button) { public void addShipButton(ShipButton button) {
@ -30,8 +28,8 @@ public class BoardDisplay extends JPanel {
} }
/** /**
* * Gibt currentShip zurück
* @return * @return currentShip
*/ */
public Ship getCurrentShip() { public Ship getCurrentShip() {
return currentShip; return currentShip;
@ -50,7 +48,7 @@ public class BoardDisplay extends JPanel {
this.gridSize = gridSize; this.gridSize = gridSize;
this.enemyBoard = enemyBoard; this.enemyBoard = enemyBoard;
// Erstellung von Spielfeld // Erstellung vom Spielfeld
for (int i = 0; i <= gridSize; i++) { for (int i = 0; i <= gridSize; i++) {
for (int j = 0; j <= gridSize; j++) { for (int j = 0; j <= gridSize; j++) {
final int x = j - 1; // Temporäre Variable final int x = j - 1; // Temporäre Variable
@ -76,20 +74,23 @@ public class BoardDisplay extends JPanel {
fields[x][y] = field; fields[x][y] = field;
add(field); add(field);
// Um Mausinteratkionen zu ermöglichen (Rechts/- Linksklick, Hover) // Um Mausinteraktionen zu ermöglichen (Rechts/- Linksklick, Hover)
field.addMouseListener(new MouseAdapter() { field.addMouseListener(new MouseAdapter() {
// Um beim "Hovern" Position zu setzten und weiterzugeben.
@Override @Override
public void mouseEntered(MouseEvent e) { public void mouseEntered(MouseEvent e) {
mousePosition = new Point(x, y); mousePosition = new Point(x, y);
paintFields(); paintFields();
} }
// Um nach "wegbewegen" der Maus wieder zu entfärben
@Override @Override
public void mouseExited(MouseEvent e) { public void mouseExited(MouseEvent e) {
paintFields(); paintFields();
} }
// Um Schiffe zu rotieren/platzieren
@Override @Override
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
if (SwingUtilities.isRightMouseButton(e)) { if (SwingUtilities.isRightMouseButton(e)) {
@ -108,9 +109,8 @@ public class BoardDisplay extends JPanel {
} }
/** /**
* TODO fertig beschreiben
* Aktuelles Schiff auswählen * Aktuelles Schiff auswählen
* @param ship * @param ship Schiff zum Auswählen
*/ */
public void selectCurrentShip(Ship ship) { public void selectCurrentShip(Ship ship) {
this.currentShip = ship; this.currentShip = ship;
@ -210,16 +210,16 @@ public class BoardDisplay extends JPanel {
switch (hit.getType()) { switch (hit.getType()) {
case HIT: case HIT:
fields[i][j].setBackground(Color.ORANGE); fields[i][j].setBackground(Color.ORANGE);
SoundHandler.playSound("hit"); //SoundHandler.playSound("hit");
break; break;
case SUNK: case SUNK:
//SoundHandler.playSound("destroyed");
case VICTORY: case VICTORY:
SoundHandler.playSound("destroyed");
fields[i][j].setBackground(Color.RED); fields[i][j].setBackground(Color.RED);
break; break;
case MISS: case MISS:
if (this.enemyBoard) { if (this.enemyBoard) {
SoundHandler.playSound("miss"); //SoundHandler.playSound("miss");
fields[i][j].setBackground(Color.BLUE); fields[i][j].setBackground(Color.BLUE);
} else { } else {
fields[i][j].setBackground(Color.CYAN); fields[i][j].setBackground(Color.CYAN);
@ -235,7 +235,7 @@ public class BoardDisplay extends JPanel {
} }
/** /**
* TODO fertig beschreiben * Ruft paintFields auf, um Felder zu aktualisieren
*/ */
public void refresh() { public void refresh() {
paintFields(); paintFields();

View File

@ -66,7 +66,6 @@ public class GameBoard extends JPanel {
Timer timer = new Timer(10, new ActionListener() { Timer timer = new Timer(10, new ActionListener() {
// Start-Grauwert (0 = Schwarz, 255 = Weiß) // Start-Grauwert (0 = Schwarz, 255 = Weiß)
private int value = 50; private int value = 50;
private boolean increasing = false; private boolean increasing = false;
@Override @Override

View File

@ -22,7 +22,8 @@ public class SoundHandler {
"miss", "./Sound/water-drip.mp3", "miss", "./Sound/water-drip.mp3",
"hit", "./Sound/hit.mp3", "hit", "./Sound/hit.mp3",
"destroyed", "./Sound/hit.mp3", "destroyed", "./Sound/hit.mp3",
"plop", "./Sound/plop.mp3" "plop", "./Sound/plop.mp3",
"loose", "./Sound/loosescreenWAH.mp3"
)); ));
/** /**