Fixed ship rotation method.

Added pulsating Effect for "kontextText"
This commit is contained in:
Joshua 2024-12-14 15:29:45 +01:00
parent bf78db9404
commit decef526da
2 changed files with 35 additions and 6 deletions

View File

@ -14,7 +14,7 @@ public class BoardDisplay extends JPanel {
private List <Ship> ships;
private Ship currentShip;
private Player player;
private boolean horizontal = true;
private boolean vertical = false;
/**
* Konstruktor der startLocalGame.
@ -74,7 +74,9 @@ public class BoardDisplay extends JPanel {
togglePlacementDirection(); // Ausrichtung ändern
} else if (SwingUtilities.isLeftMouseButton(e)) {
Point o = new Point(x, y);
currentShip.setHorizontal(vertical);
handleFieldClick(o); // Linksklick -> Schiff platzieren
vertical = false; // TODO nur nach auswahl von neuem Modul wieder auf false setzten
}
}
});
@ -157,8 +159,8 @@ public class BoardDisplay extends JPanel {
* Wechselt die Platzierungsrichtung zwischen horizontal und vertikal.
*/
private void togglePlacementDirection() {
horizontal = !horizontal;
String direction = horizontal ? "horizontal" : "vertikal";
vertical = !vertical;
String direction = vertical ? "vertikal" : "horizontal";
System.out.println("Platzierungsrichtung geändert zu: " + direction);
}

View File

@ -9,7 +9,7 @@ import java.awt.event.MouseAdapter;
import java.util.List;
// TODO wenn rechtklick auf board dann schiff rotation ändern UND Readybutton farbe Readybutton kontexttext und Spielernamen anzeigen
// TODO Readybutton farbe Readybutton kontexttext und Spielernamen anzeigen
/**
* Das GameBoard dient als Panel, in dem das tatsächliche Spiel stattfindet.
* Der Benutzer kann hier seine Schiffe platzieren, das Spiel starten etc.
@ -25,8 +25,7 @@ public class GameBoard extends JPanel {
// Labels
JLabel frameTitle = new JLabel("GameBoard");
JLabel kontextText = new JLabel("Beispielhafter Kontext-Text");
//kontextText.setFont(new Font("Roboto", Font.BOLD, 24)); //TODO setFont fixen
JLabel kontextText = new JLabel("Bitte Schiffe setzten");
JButton backButton = new JButton(backButtonIcon);
// Eigene ModulButtons
@ -57,6 +56,31 @@ public class GameBoard extends JPanel {
}
}
// Timer für pulsierenden Effekt
Timer timer = new Timer(10, new ActionListener() {
private int grayValue = 50; // Start-Grauwert (0 = Schwarz, 255 = Weiß)
private boolean increasing = false; // Richtung des Pulsierens
@Override
public void actionPerformed(ActionEvent e) {
// Grauwert aktualisieren
kontextText.setForeground(new Color(grayValue, grayValue, grayValue));
// Grauwert erhöhen oder verringern
if (increasing) {
grayValue++;
if (grayValue >= 90) {
increasing = false; // Richtung ändern
}
} else {
grayValue--;
if (grayValue <= 0) {
increasing = true; // Richtung ändern
}
}
}
});
/**
* TODO Funktion beschreiben etc.
* @param frame
@ -78,6 +102,7 @@ public class GameBoard extends JPanel {
JPanel headerPanel = new JPanel();
headerPanel.setLayout(new BorderLayout());
headerPanel.add(kontextText, BorderLayout.WEST);
kontextText.setFont(new Font("Roboto", Font.BOLD, 30)); //TODO setFont fixen
headerPanel.add(backButton, BorderLayout.EAST);
JPanel leftButtonsPanel = new JPanel();
@ -147,5 +172,7 @@ public class GameBoard extends JPanel {
add(rightButtonsPanel, BorderLayout.EAST);
add(headerPanel, BorderLayout.NORTH);
add(centerPanel, BorderLayout.CENTER);
timer.start();
}
}