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

View File

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

View File

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