Änderung an Hintergund und Buttonfarbe
parent
7139741018
commit
f440ecb839
|
@ -6,23 +6,6 @@ import java.util.List;
|
||||||
|
|
||||||
public class BoardLoader {
|
public class BoardLoader {
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Gibt eine Liste aller verfügbaren Spielfeld-Dateien im Package zurück.
|
|
||||||
* @return Eine Liste von relativen Pfaden zu CSV-Dateien.
|
|
||||||
*/
|
|
||||||
/*public static List<String> loadBoardsAsList() {
|
|
||||||
// Harte Kodierung der bekannten Dateien
|
|
||||||
return List.of(
|
|
||||||
"Hitori4x4_leicht.csv",
|
|
||||||
"Hitori5x5leicht.csv",
|
|
||||||
"Hitori8x8leicht.csv",
|
|
||||||
"Hitori8x8medium.csv",
|
|
||||||
"Hitori10x10medium.csv",
|
|
||||||
"Hitori15x15_medium.csv"
|
|
||||||
);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
public static List<String> loadBoardsAsList() {
|
public static List<String> loadBoardsAsList() {
|
||||||
List<String> boardFiles = new ArrayList<>();
|
List<String> boardFiles = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -3,7 +3,8 @@ package PR2.HitoriSpiel.GUI;
|
||||||
import PR2.HitoriSpiel.Domain.StateManager;
|
import PR2.HitoriSpiel.Domain.StateManager;
|
||||||
import PR2.HitoriSpiel.Domain.HitoriBoard;
|
import PR2.HitoriSpiel.Domain.HitoriBoard;
|
||||||
import PR2.HitoriSpiel.Domain.HitoriCell;
|
import PR2.HitoriSpiel.Domain.HitoriCell;
|
||||||
import PR2.HitoriSpiel.Domain.HitoriValidator;
|
import PR2.HitoriSpiel.Utils.HighscoreManager;
|
||||||
|
import PR2.HitoriSpiel.Utils.Setup;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
@ -64,14 +65,14 @@ public class GameBoard extends JPanel {
|
||||||
private JPanel createControlPanel() {
|
private JPanel createControlPanel() {
|
||||||
JPanel controlPanel = new JPanel();
|
JPanel controlPanel = new JPanel();
|
||||||
|
|
||||||
JButton resetButton = createButton("Zurücksetzen", 150, 30);
|
JButton resetButton = Setup.createGameBoardButton("Zurücksetzen", 150, 30);
|
||||||
resetButton.addActionListener(e -> {
|
resetButton.addActionListener(e -> {
|
||||||
saveStateForUndo();
|
saveStateForUndo();
|
||||||
resetBoard();
|
resetBoard();
|
||||||
refreshBoard();
|
refreshBoard();
|
||||||
});
|
});
|
||||||
|
|
||||||
JButton undoButton = createButton("Undo", 80, 30);
|
JButton undoButton = Setup.createGameBoardButton("Undo", 80, 30);
|
||||||
undoButton.addActionListener(e -> {
|
undoButton.addActionListener(e -> {
|
||||||
int[][] previousState = stateManager.undo(board.getNumbers());
|
int[][] previousState = stateManager.undo(board.getNumbers());
|
||||||
if (previousState != null) {
|
if (previousState != null) {
|
||||||
|
@ -82,7 +83,7 @@ public class GameBoard extends JPanel {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
JButton redoButton = createButton("Redo", 80, 30);
|
JButton redoButton = Setup.createGameBoardButton("Redo", 80, 30);
|
||||||
redoButton.addActionListener(e -> {
|
redoButton.addActionListener(e -> {
|
||||||
int[][] nextState = stateManager.redo(board.getNumbers());
|
int[][] nextState = stateManager.redo(board.getNumbers());
|
||||||
if (nextState != null) {
|
if (nextState != null) {
|
||||||
|
@ -93,7 +94,7 @@ public class GameBoard extends JPanel {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
JButton validateButton = createButton("Validieren", 100, 30);
|
JButton validateButton = Setup.createGameBoardButton("Lösen", 80, 30);
|
||||||
validateButton.addActionListener(e -> {
|
validateButton.addActionListener(e -> {
|
||||||
if (validateCurrentBoard()) {
|
if (validateCurrentBoard()) {
|
||||||
stopTimer();
|
stopTimer();
|
||||||
|
@ -103,7 +104,7 @@ public class GameBoard extends JPanel {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
JButton pauseButton = createButton("Pause", 100, 30);
|
JButton pauseButton = Setup.createGameBoardButton("Pause", 80, 30);
|
||||||
pauseButton.addActionListener(e -> {
|
pauseButton.addActionListener(e -> {
|
||||||
stopTimer();
|
stopTimer();
|
||||||
showPauseMenu();
|
showPauseMenu();
|
||||||
|
@ -226,6 +227,37 @@ public class GameBoard extends JPanel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void saveHighscore() {
|
||||||
|
String playerName = JOptionPane.showInputDialog(this,
|
||||||
|
"Bitte geben Sie Ihren Namen ein:",
|
||||||
|
"Highscore speichern",
|
||||||
|
JOptionPane.PLAIN_MESSAGE);
|
||||||
|
|
||||||
|
// Überprüfen, ob ein Name eingegeben wurde
|
||||||
|
if (playerName == null || playerName.trim().isEmpty()) {
|
||||||
|
JOptionPane.showMessageDialog(this,
|
||||||
|
"Highscore wurde nicht gespeichert. Kein Name eingegeben.",
|
||||||
|
"Info",
|
||||||
|
JOptionPane.INFORMATION_MESSAGE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Berechne die verstrichene Zeit
|
||||||
|
int elapsedTime = (int) ((System.currentTimeMillis() - startTime) / 1000); // Zeit in Sekunden
|
||||||
|
|
||||||
|
// Spielfeldname (oder eine Beschreibung)
|
||||||
|
String boardName = "Aktuelles Spielfeld"; // Falls ein spezifischer Name verfügbar ist, ersetzen
|
||||||
|
|
||||||
|
// Speichere den Highscore mit dem HighscoreManager
|
||||||
|
HighscoreManager.saveHighscore(playerName, elapsedTime, boardName);
|
||||||
|
|
||||||
|
// Zeige eine Bestätigung an
|
||||||
|
JOptionPane.showMessageDialog(this,
|
||||||
|
"Highscore erfolgreich gespeichert!",
|
||||||
|
"Erfolg",
|
||||||
|
JOptionPane.INFORMATION_MESSAGE);
|
||||||
|
}
|
||||||
|
|
||||||
private void returnToMainMenu() {
|
private void returnToMainMenu() {
|
||||||
/// Eltern-Frame abrufen
|
/// Eltern-Frame abrufen
|
||||||
JFrame parentFrame = (JFrame) SwingUtilities.getWindowAncestor(this);
|
JFrame parentFrame = (JFrame) SwingUtilities.getWindowAncestor(this);
|
||||||
|
|
|
@ -2,12 +2,11 @@ package PR2.HitoriSpiel.GUI;
|
||||||
|
|
||||||
import PR2.HitoriSpiel.Domain.HitoriBoard;
|
import PR2.HitoriSpiel.Domain.HitoriBoard;
|
||||||
import PR2.HitoriSpiel.Domain.HitoriSolutionLoader;
|
import PR2.HitoriSpiel.Domain.HitoriSolutionLoader;
|
||||||
|
import PR2.HitoriSpiel.Utils.Setup;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
@ -19,6 +18,7 @@ public class StartMenu extends JPanel {
|
||||||
public StartMenu(JFrame parentFrame) {
|
public StartMenu(JFrame parentFrame) {
|
||||||
this.parentFrame = parentFrame;
|
this.parentFrame = parentFrame;
|
||||||
setLayout(new GridBagLayout());
|
setLayout(new GridBagLayout());
|
||||||
|
Setup.stylePanel(this); // Hintergrundfarbe setzen
|
||||||
|
|
||||||
//mainPanel = new JPanel(new GridBagLayout());
|
//mainPanel = new JPanel(new GridBagLayout());
|
||||||
GridBagConstraints gbc = new GridBagConstraints();
|
GridBagConstraints gbc = new GridBagConstraints();
|
||||||
|
@ -28,17 +28,16 @@ public class StartMenu extends JPanel {
|
||||||
gbc.anchor = GridBagConstraints.CENTER; // Buttons zentrieren
|
gbc.anchor = GridBagConstraints.CENTER; // Buttons zentrieren
|
||||||
|
|
||||||
JLabel titleLabel = new JLabel("Willkommen im Hitori-Spiel!");
|
JLabel titleLabel = new JLabel("Willkommen im Hitori-Spiel!");
|
||||||
titleLabel.setFont(new Font("Arial", Font.BOLD, 16));
|
Setup.styleLabel(titleLabel);
|
||||||
titleLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
|
||||||
add(titleLabel, gbc);
|
add(titleLabel, gbc);
|
||||||
|
|
||||||
|
|
||||||
// Buttons erstellen
|
// Buttons erstellen
|
||||||
JButton continueButton = createButton("Spiel fortsetzen", 200, 30);
|
JButton continueButton = Setup.createButton("Spiel fortsetzen", 300, 50);
|
||||||
JButton selectBoardButton = createButton("Spielfeld aussuchen", 200, 30);
|
JButton selectBoardButton = Setup.createButton("Spielfeld aussuchen", 300, 50);
|
||||||
JButton randomBoardButton = createButton("Zufälliges Spielfeld", 200, 30);
|
JButton randomBoardButton = Setup.createButton("Zufälliges Spielfeld", 300, 50);
|
||||||
JButton highscorelistButton = createButton("Highscoreliste anschauen", 200, 30);
|
JButton highscorelistButton = Setup.createButton("Highscoreliste anschauen", 300, 50);
|
||||||
JButton exitButton = createButton("Spiel beenden", 200, 30);
|
JButton exitButton = Setup.createButton("Spiel beenden", 300, 50);
|
||||||
|
|
||||||
|
|
||||||
add(continueButton, gbc);
|
add(continueButton, gbc);
|
||||||
|
@ -60,7 +59,7 @@ public class StartMenu extends JPanel {
|
||||||
JOptionPane.showMessageDialog(this, "Spiel fortsetzen wurde angeklickt");
|
JOptionPane.showMessageDialog(this, "Spiel fortsetzen wurde angeklickt");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void selectBoard() {
|
protected void selectBoard() {
|
||||||
|
|
||||||
List<String> boardFileNames = BoardLoader.loadBoardsAsList();
|
List<String> boardFileNames = BoardLoader.loadBoardsAsList();
|
||||||
System.out.println("Verfügbare Spielfelder: " + boardFileNames);
|
System.out.println("Verfügbare Spielfelder: " + boardFileNames);
|
||||||
|
@ -96,7 +95,7 @@ public class StartMenu extends JPanel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void randomBoard() {
|
protected void randomBoard() {
|
||||||
List<String> boardFileNames = BoardLoader.loadBoardsAsList();
|
List<String> boardFileNames = BoardLoader.loadBoardsAsList();
|
||||||
if (boardFileNames == null || boardFileNames.isEmpty()) {
|
if (boardFileNames == null || boardFileNames.isEmpty()) {
|
||||||
JOptionPane.showMessageDialog(this, "Keine Spielfelder gefunden.", "Fehler", JOptionPane.ERROR_MESSAGE);
|
JOptionPane.showMessageDialog(this, "Keine Spielfelder gefunden.", "Fehler", JOptionPane.ERROR_MESSAGE);
|
||||||
|
@ -109,16 +108,10 @@ public class StartMenu extends JPanel {
|
||||||
|
|
||||||
|
|
||||||
private void highscorelist() {
|
private void highscorelist() {
|
||||||
// TODO: Logik zur Anzeige der Highscoreliste implementieren
|
new HighscoreDialog((JFrame) SwingUtilities.getWindowAncestor(this)).setVisible(true);
|
||||||
JOptionPane.showMessageDialog(this, "Highscoreliste wurde angeklickt");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hilfsmethoden
|
// Hilfsmethoden
|
||||||
private JButton createButton(String text, int width, int height) {
|
|
||||||
JButton button = new JButton(text);
|
|
||||||
button.setPreferredSize(new Dimension(width, height));
|
|
||||||
return button;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadGameBoard(GameBoard gameBoard, List<String> solutionCoordinates) {
|
private void loadGameBoard(GameBoard gameBoard, List<String> solutionCoordinates) {
|
||||||
removeAll();
|
removeAll();
|
||||||
|
|
|
@ -0,0 +1,113 @@
|
||||||
|
package PR2.HitoriSpiel.Utils;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.MouseAdapter;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
|
||||||
|
public class Setup {
|
||||||
|
|
||||||
|
// Standardfarben
|
||||||
|
public static final Color BACKGROUND_COLOR = new Color(230, 230, 250);
|
||||||
|
public static final Color BUTTON_COLOR = new Color(75, 0, 130);
|
||||||
|
public static final Color BUTTON_TEXT_COLOR = new Color(230, 230, 250);
|
||||||
|
public static final Color BUTTON_HOVER_COLOR = new Color(64, 224, 208);
|
||||||
|
|
||||||
|
// Schriftart für Buttons
|
||||||
|
public static final Font BUTTON_FONT = new Font("Monospaced", Font.PLAIN, 18);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Erstellt einen standardisierten Button mit den voreingestellten Farben und Effekten.
|
||||||
|
*
|
||||||
|
* @param text Der Text des Buttons.
|
||||||
|
* @param width Breite des Buttons.
|
||||||
|
* @param height Höhe des Buttons.
|
||||||
|
* @return Der konfigurierte JButton.
|
||||||
|
*/
|
||||||
|
public static JButton createButton(String text, int width, int height) {
|
||||||
|
JButton button = new JButton(text);
|
||||||
|
button.setPreferredSize(new Dimension(width, height));
|
||||||
|
button.setBackground(BUTTON_COLOR);
|
||||||
|
button.setForeground(BUTTON_TEXT_COLOR);
|
||||||
|
button.setFocusPainted(false);
|
||||||
|
button.setFont(BUTTON_FONT);
|
||||||
|
|
||||||
|
// Hover-Effekt hinzufügen
|
||||||
|
button.addMouseListener(new MouseAdapter() {
|
||||||
|
@Override
|
||||||
|
public void mouseEntered(MouseEvent e) {
|
||||||
|
button.setBackground(BUTTON_HOVER_COLOR);
|
||||||
|
button.setForeground(Color.BLACK); // Schriftfarbe ändern
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseExited(MouseEvent e) {
|
||||||
|
button.setBackground(BUTTON_COLOR); // Hintergrundfarbe zurücksetzen
|
||||||
|
button.setForeground(BUTTON_TEXT_COLOR); // Schriftfarbe zurücksetzen
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return button;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Spezielle Farben für GameBoard
|
||||||
|
public static final Color GAME_BUTTON_COLOR = new Color(75, 0, 130);
|
||||||
|
public static final Color GAME_BUTTON_HOVER_COLOR = new Color(64, 224, 208);
|
||||||
|
public static final Color GAME_BUTTON_TEXT_COLOR = new Color(230, 230, 250);
|
||||||
|
|
||||||
|
// Schriftart für Buttons
|
||||||
|
public static final Font GAME_BOARD_BUTTON_FONT = new Font("Monospaced", Font.PLAIN, 14);
|
||||||
|
/**
|
||||||
|
* Erstellt einen Button mit Stil für GameBoard.
|
||||||
|
*
|
||||||
|
* @param text Der Text des Buttons.
|
||||||
|
* @param width Breite des Buttons.
|
||||||
|
* @param height Höhe des Buttons.
|
||||||
|
* @return Der konfigurierte JButton.
|
||||||
|
*/
|
||||||
|
public static JButton createGameBoardButton(String text, int width, int height) {
|
||||||
|
JButton button = new JButton(text);
|
||||||
|
button.setPreferredSize(new Dimension(width, height));
|
||||||
|
button.setBackground(GAME_BUTTON_COLOR);
|
||||||
|
button.setForeground(GAME_BUTTON_TEXT_COLOR);
|
||||||
|
button.setFont(GAME_BOARD_BUTTON_FONT);
|
||||||
|
button.setFocusPainted(false);
|
||||||
|
|
||||||
|
// Hover-Effekt
|
||||||
|
button.addMouseListener(new MouseAdapter() {
|
||||||
|
@Override
|
||||||
|
public void mouseEntered(MouseEvent e) {
|
||||||
|
button.setBackground(GAME_BUTTON_HOVER_COLOR);
|
||||||
|
button.setForeground(Color.BLACK); // Schriftfarbe ändern
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseExited(MouseEvent e) {
|
||||||
|
button.setBackground(GAME_BUTTON_COLOR);
|
||||||
|
button.setForeground(GAME_BUTTON_TEXT_COLOR); // Schriftfarbe zurücksetzen
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return button;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setzt den Hintergrund und die Schriftfarbe für ein JPanel.
|
||||||
|
*
|
||||||
|
* @param panel Das Panel, dessen Stil angepasst wird.
|
||||||
|
*/
|
||||||
|
public static void stylePanel(JPanel panel) {
|
||||||
|
panel.setBackground(BACKGROUND_COLOR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setzt die Farbe und Schriftart eines JLabels.
|
||||||
|
*
|
||||||
|
* @param label Das Label, dessen Stil angepasst wird.
|
||||||
|
*/
|
||||||
|
public static void styleLabel(JLabel label) {
|
||||||
|
label.setForeground(new Color(75, 0, 130));
|
||||||
|
label.setFont(new Font("Monospaced", Font.PLAIN, 30));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
package PR2.HitoriSpiel.test.GUI;
|
||||||
|
|
||||||
|
public class PauseMenuTest {
|
||||||
|
}
|
Loading…
Reference in New Issue