Compare commits
4 Commits
5770d13cdc
...
d0c267f7b0
| Author | SHA1 | Date |
|---|---|---|
|
|
d0c267f7b0 | |
|
|
4cee12cfb9 | |
|
|
8447ce5fe3 | |
|
|
6d3154d0e3 |
|
|
@ -29,7 +29,7 @@ public class CreativeController {
|
|||
map.put("WHITE_ROOK", 'R');
|
||||
map.put("WHITE_BISHOP", 'B');
|
||||
map.put("WHITE_KNIGHT", 'N');
|
||||
map.put("WHITE_PAWN", 'P');
|
||||
map.put("WHITE_PAWN", 'P');
|
||||
return map;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,11 +11,12 @@ import javax.swing.BorderFactory;
|
|||
import com.github.bhlangonijr.chesslib.game.Game;
|
||||
|
||||
import de.hs_mannheim.informatik.chess.model.ChessEngine;
|
||||
import de.hs_mannheim.informatik.chess.model.GameMode;
|
||||
import de.hs_mannheim.informatik.chess.model.MoveDTO;
|
||||
import de.hs_mannheim.informatik.chess.model.PieceDTO;
|
||||
import de.hs_mannheim.informatik.chess.model.Timer;
|
||||
import de.hs_mannheim.informatik.chess.model.BoardDTO;
|
||||
import de.hs_mannheim.informatik.chess.view.GameGui;
|
||||
import de.hs_mannheim.informatik.chess.view.MainGui;
|
||||
|
||||
public class GameController {
|
||||
GameGui gui;
|
||||
|
|
@ -25,13 +26,24 @@ public class GameController {
|
|||
private boolean gameOver = false;
|
||||
private int selectedRow = -1, selectedCol = -1;
|
||||
private List<int[]> highlightedFields = new ArrayList<>();
|
||||
private GameMode gameMode;
|
||||
|
||||
public GameController(GameGui gui, ChessEngine engine, GameEndCallback callback, GameMode gameMode) {
|
||||
this(gui, engine, callback); // ruft anderen Konstruktor auf
|
||||
this.gameMode = gameMode;
|
||||
if (gameMode != null) {
|
||||
engine.initTimers(gameMode.minutes, gameMode.incrementSeconds);
|
||||
time();
|
||||
}
|
||||
}
|
||||
|
||||
// Für Creative/PGN-Mode (ohne Zeit)
|
||||
public GameController(GameGui gui, ChessEngine engine, GameEndCallback callback) {
|
||||
this.gui = gui;
|
||||
this.engine = engine;
|
||||
this.callback = callback;
|
||||
engine.initTimers(3, 0);
|
||||
time();
|
||||
this.gameMode = null;
|
||||
// KEINE Timer initialisieren
|
||||
initListeners();
|
||||
updateGuiBoard();
|
||||
}
|
||||
|
|
@ -126,7 +138,6 @@ public class GameController {
|
|||
// --- AUFGEBEN-BUTTON ---
|
||||
gui.getResignButton().addActionListener(e -> {
|
||||
if (gameOver) return;
|
||||
|
||||
int answer = javax.swing.JOptionPane.showConfirmDialog(
|
||||
null,
|
||||
"Willst du wirklich aufgeben?",
|
||||
|
|
@ -137,16 +148,14 @@ public class GameController {
|
|||
gameOver = true;
|
||||
String winner = engine.getCurrentPlayer().equals("WHITE") ? "SCHWARZ" : "WEIß";
|
||||
gui.displayMessage(winner + " gewinnt durch Aufgabe!");
|
||||
engine.getWhiteTimer().stop();
|
||||
engine.getBlackTimer().stop();
|
||||
if (engine.getWhiteTimer() != null) engine.getWhiteTimer().stop();
|
||||
if (engine.getBlackTimer() != null) engine.getBlackTimer().stop();
|
||||
askForRestart();
|
||||
}
|
||||
});
|
||||
|
||||
// --- PATT-/REMIS-BUTTON ---
|
||||
gui.getDrawButton().addActionListener(e -> {
|
||||
if (gameOver) return;
|
||||
|
||||
int answer = javax.swing.JOptionPane.showConfirmDialog(
|
||||
null,
|
||||
"Remis anbieten? (Das Spiel endet sofort unentschieden)",
|
||||
|
|
@ -156,8 +165,8 @@ public class GameController {
|
|||
if (answer == javax.swing.JOptionPane.YES_OPTION) {
|
||||
gameOver = true;
|
||||
gui.displayMessage("Remis! (durch Einigung)");
|
||||
engine.getWhiteTimer().stop();
|
||||
engine.getBlackTimer().stop();
|
||||
if (engine.getWhiteTimer() != null) engine.getWhiteTimer().stop();
|
||||
if (engine.getBlackTimer() != null) engine.getBlackTimer().stop();
|
||||
askForRestart();
|
||||
}
|
||||
});
|
||||
|
|
@ -279,6 +288,8 @@ public class GameController {
|
|||
|
||||
updateGuiBoard();
|
||||
gui.updateMoveList(engine.getMoveListStringsGrouped());
|
||||
|
||||
|
||||
|
||||
// ---- HIER ist die Matt/Patt/Remis-Prüfung ----
|
||||
if (engine.isMated()) {
|
||||
|
|
@ -305,12 +316,25 @@ public class GameController {
|
|||
}
|
||||
|
||||
private void switchTimers() {
|
||||
GameMode mode = engine.getGameMode();
|
||||
Timer whiteTimer = engine.getWhiteTimer();
|
||||
Timer blackTimer = engine.getBlackTimer();
|
||||
|
||||
// Wenn KEIN Modus (also kein Timer): NICHTS machen!
|
||||
if (mode == null || whiteTimer == null || blackTimer == null) return;
|
||||
|
||||
if (engine.getCurrentPlayer().equals("WHITE")) {
|
||||
engine.getBlackTimer().stop();
|
||||
engine.getWhiteTimer().start();
|
||||
if (mode.incrementSeconds > 0) {
|
||||
blackTimer.addSeconds(mode.incrementSeconds);
|
||||
}
|
||||
blackTimer.stop();
|
||||
whiteTimer.start();
|
||||
} else {
|
||||
engine.getWhiteTimer().stop();
|
||||
engine.getBlackTimer().start();
|
||||
if (mode.incrementSeconds > 0) {
|
||||
whiteTimer.addSeconds(mode.incrementSeconds);
|
||||
}
|
||||
whiteTimer.stop();
|
||||
blackTimer.start();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import de.hs_mannheim.informatik.chess.view.PgnGui;
|
|||
import de.hs_mannheim.informatik.chess.view.PgnSelectionGui;
|
||||
import de.hs_mannheim.informatik.chess.view.CreativeGui;
|
||||
import de.hs_mannheim.informatik.chess.view.GameGui;
|
||||
import de.hs_mannheim.informatik.chess.view.GameModeSelector;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
|
@ -15,6 +16,7 @@ import javax.swing.JOptionPane;
|
|||
import com.github.bhlangonijr.chesslib.game.Game;
|
||||
|
||||
import de.hs_mannheim.informatik.chess.model.ChessEngine;
|
||||
import de.hs_mannheim.informatik.chess.model.GameMode;
|
||||
|
||||
public class MainController {
|
||||
private MainGui mainGui;
|
||||
|
|
@ -28,9 +30,11 @@ public class MainController {
|
|||
}
|
||||
|
||||
private void startNormalMode() {
|
||||
|
||||
GameMode mode = GameModeSelector.selectGameMode();
|
||||
mainGui.close();
|
||||
GameGui gameGui = new GameGui();
|
||||
ChessEngine engine = new ChessEngine();
|
||||
ChessEngine engine = new ChessEngine(mode);
|
||||
GameEndCallback callback = new GameEndCallback() {
|
||||
public void onNewGameRequested() {
|
||||
startNormalMode();
|
||||
|
|
@ -39,7 +43,7 @@ public class MainController {
|
|||
new MainController();
|
||||
}
|
||||
};
|
||||
new GameController(gameGui, engine, callback);
|
||||
new GameController(gameGui, engine, callback,mode);
|
||||
}
|
||||
|
||||
private void startCreativeMode() {
|
||||
|
|
@ -47,6 +51,25 @@ public class MainController {
|
|||
CreativeGui creativegui = new CreativeGui();
|
||||
ChessEngine engine = new ChessEngine();
|
||||
new CreativeController(creativegui, engine);
|
||||
|
||||
creativegui.setStartGameCallback(fen -> {
|
||||
// 1. Modus-Auswahl-Dialog zeigen!
|
||||
GameMode mode = GameModeSelector.selectGameMode(); // (Dialog, wie beim Normal Mode)
|
||||
|
||||
if (mode == null) return; // User hat abgebrochen → nichts machen
|
||||
|
||||
|
||||
ChessEngine newEngine = new ChessEngine(mode); // Engine mit Modus (Timer)
|
||||
newEngine.setPositionFromFEN(fen);
|
||||
|
||||
GameGui gameGui = new GameGui();
|
||||
GameEndCallback callback = new GameEndCallback() {
|
||||
public void onNewGameRequested() { startCreativeMode(); }
|
||||
public void onReturnToMenu() { new MainController(); }
|
||||
};
|
||||
new GameController(gameGui, newEngine, callback, mode); // mit Timer/ohne je nach Modus
|
||||
creativegui.close();
|
||||
});
|
||||
}
|
||||
|
||||
private void startLoadGameMode() {
|
||||
|
|
@ -68,5 +91,6 @@ public class MainController {
|
|||
JOptionPane.showMessageDialog(null, "Fehler beim Laden der PGN-Datei:\n" + ex.getMessage());
|
||||
}
|
||||
}
|
||||
mainGui.close();
|
||||
}
|
||||
}
|
||||
|
|
@ -65,7 +65,8 @@ public class PgnController {
|
|||
public void updateGuiBoard() {
|
||||
BoardDTO board = engine.getBoardAsDTO();
|
||||
gui.updateBoard(board);
|
||||
gui.updateMoveList(engine.getMoveListStringsGrouped());
|
||||
gui.updateMoveList(engine.getMoveListStringsGrouped());
|
||||
gui.setOpeningLabel(engine.getOpeningName());
|
||||
}
|
||||
|
||||
private void resetFieldBackground(int row, int col) {
|
||||
|
|
|
|||
|
|
@ -25,18 +25,30 @@ import com.github.bhlangonijr.chesslib.Side;
|
|||
public class ChessEngine {
|
||||
private Board board;
|
||||
private List<Move> moves = new ArrayList<>();
|
||||
private String initialFen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
|
||||
private static final Logger logger = Logger.getLogger(ChessEngine.class.getName());
|
||||
|
||||
private int currentMoveIndex = 0;
|
||||
private Timer whiteTimer;
|
||||
private Timer blackTimer;
|
||||
private final GameMode mode;
|
||||
|
||||
|
||||
private Opening detectedOpening = null;
|
||||
|
||||
public ChessEngine() {
|
||||
public ChessEngine() {
|
||||
this.mode = null;
|
||||
logging();
|
||||
board = new Board();
|
||||
}
|
||||
|
||||
public ChessEngine(GameMode mode) {
|
||||
this.mode = mode;
|
||||
whiteTimer = new Timer(mode.minutes, mode.seconds);
|
||||
blackTimer = new Timer(mode.minutes, mode.seconds);
|
||||
logging();
|
||||
board = new Board();
|
||||
}
|
||||
public boolean move(MoveDTO move) {
|
||||
String from = "" + (char)('A' + move.getFromCol()) + (8 - move.getFromRow());
|
||||
String to = "" + (char)('A' + move.getToCol()) + (8 - move.getToRow());
|
||||
|
|
@ -188,9 +200,9 @@ public class ChessEngine {
|
|||
}
|
||||
|
||||
public void setPositionToMoveIndex(int idx) {
|
||||
// Neues Board erzeugen
|
||||
logger.info("Setze Board auf Zug-Index: " + idx);
|
||||
logger.info("Setze Board auf Zug-Index: " + idx);
|
||||
board = new Board();
|
||||
board.loadFromFen(initialFen); // Statt new Board() -> initialFen!
|
||||
for (int i = 0; i < idx; i++) {
|
||||
board.doMove(moves.get(i));
|
||||
}
|
||||
|
|
@ -199,7 +211,6 @@ public class ChessEngine {
|
|||
String playedMovesUci = movesToUciString(moves.subList(0, idx));
|
||||
detectedOpening = Opening.detect(playedMovesUci);
|
||||
}
|
||||
|
||||
public int getCurrentMoveIndex() {
|
||||
logger.info("Hole aktuellen Zug-Index: " + currentMoveIndex);
|
||||
return currentMoveIndex;
|
||||
|
|
@ -220,6 +231,7 @@ public class ChessEngine {
|
|||
|
||||
public void setPositionFromFEN(String fen) {
|
||||
board.loadFromFen(fen);
|
||||
initialFen = fen;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -263,7 +275,7 @@ public class ChessEngine {
|
|||
|
||||
logger.info("ChessEngine wurde initialisiert.");
|
||||
}
|
||||
|
||||
|
||||
public List<Game> loadGamesFromPgn(String path) throws IOException {
|
||||
|
||||
PgnHolder pgnHolder = new PgnHolder(path);
|
||||
|
|
@ -411,6 +423,17 @@ public class ChessEngine {
|
|||
}
|
||||
|
||||
public Timer getWhiteTimer() { return whiteTimer; }
|
||||
public Timer getBlackTimer() { return blackTimer; }
|
||||
|
||||
public Timer getBlackTimer() { return blackTimer; }
|
||||
|
||||
|
||||
public GameMode getGameMode() {
|
||||
// TODO Auto-generated method stub
|
||||
return mode;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
package de.hs_mannheim.informatik.chess.model;
|
||||
|
||||
public enum GameMode {
|
||||
CLASSIC(3, 0, 0),
|
||||
RAPID(5, 0, 0),
|
||||
BULLET(1, 0, 10); // 1 Minute + 10 Sek Inkrement
|
||||
|
||||
public final int minutes;
|
||||
public final int seconds;
|
||||
public final int incrementSeconds;
|
||||
|
||||
GameMode(int minutes, int seconds, int incrementSeconds) {
|
||||
this.minutes = minutes;
|
||||
this.seconds = seconds;
|
||||
this.incrementSeconds = incrementSeconds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return switch (this) {
|
||||
case CLASSIC -> "3 Minuten (klassisch)";
|
||||
case RAPID -> "5 Minuten (rapid)";
|
||||
case BULLET -> "1 Minute + 10 Sek Inkrement";
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -56,6 +56,10 @@ public class Timer {
|
|||
public int getSecondsLeft() {
|
||||
return secondsLeft;
|
||||
}
|
||||
|
||||
public void addSeconds(int seconds) {
|
||||
this.secondsLeft += seconds;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,11 @@ import java.awt.*;
|
|||
import java.util.HashMap;
|
||||
|
||||
public class CreativeGui {
|
||||
|
||||
public interface StartGameCallback {
|
||||
void onStartGame(String fen);
|
||||
}
|
||||
|
||||
private boolean isFlipped = false;
|
||||
|
||||
private JFrame frame;
|
||||
|
|
@ -13,6 +18,12 @@ public class CreativeGui {
|
|||
private JTextField fenField;
|
||||
private JButton updateBtn;
|
||||
private JButton flipBoardButton;
|
||||
|
||||
private boolean closedByUser = true;
|
||||
|
||||
private StartGameCallback startGameCallback;
|
||||
|
||||
private JButton startGameButton;
|
||||
|
||||
public static final HashMap<String, String> UNICODE_MAP = new HashMap<String, String>() {{
|
||||
put("BLACK_KING", "\u265A"); put("BLACK_QUEEN", "\u265B");
|
||||
|
|
@ -41,7 +52,7 @@ public class CreativeGui {
|
|||
// LINKS: chessPanel (Board+Toolbars)
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = 0;
|
||||
gbc.weightx = 0.6;
|
||||
gbc.weightx = 0.7;
|
||||
gbc.weighty = 1.0;
|
||||
gbc.insets = new Insets(5, 5, 5, 0);
|
||||
gbc.fill = GridBagConstraints.BOTH;
|
||||
|
|
@ -50,12 +61,21 @@ public class CreativeGui {
|
|||
// RECHTS: FEN & Optionen
|
||||
gbc.gridx = 1;
|
||||
gbc.gridy = 0;
|
||||
gbc.weightx = 0.4;
|
||||
gbc.weightx = 0.3;
|
||||
gbc.weighty = 1.0;
|
||||
gbc.insets = new Insets(5, 0, 5, 5);
|
||||
gbc.fill = GridBagConstraints.BOTH;
|
||||
mainPanel.add(fenPanel(), gbc);
|
||||
|
||||
|
||||
frame.addWindowListener(new java.awt.event.WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosed(java.awt.event.WindowEvent e) {
|
||||
if (closedByUser) {
|
||||
new de.hs_mannheim.informatik.chess.controller.MainController();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
frame.setContentPane(mainPanel);
|
||||
frame.setVisible(true);
|
||||
}
|
||||
|
|
@ -72,7 +92,7 @@ public class CreativeGui {
|
|||
btn.setFocusPainted(false);
|
||||
btn.setPreferredSize(new Dimension(70, 70));
|
||||
btn.setBackground(white ? LIGHT : DARK);
|
||||
btn.setBorder(BorderFactory.createEmptyBorder(20, 0, 20, 0));
|
||||
btn.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
|
||||
String key = prefix + type;
|
||||
btn.addActionListener(e -> selectedPiece = key);
|
||||
panel.add(btn);
|
||||
|
|
@ -105,47 +125,76 @@ public class CreativeGui {
|
|||
}
|
||||
|
||||
private JPanel chessPanel() {
|
||||
JPanel chessPanel = new JPanel(new GridBagLayout());
|
||||
JPanel chessPanel = new JPanel(new BorderLayout());
|
||||
chessPanel.setBackground(new Color(0x1b263b));
|
||||
GridBagConstraints gbc = new GridBagConstraints();
|
||||
|
||||
// Toolbar oben
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = 0;
|
||||
gbc.fill = GridBagConstraints.HORIZONTAL;
|
||||
chessPanel.add(toolbarPanel(false), gbc);
|
||||
// Board UND Toolbars in EINEM Panel, damit sie linksbündig mit dem Brett starten!
|
||||
JPanel boardAndToolbars = new JPanel(new BorderLayout());
|
||||
boardAndToolbars.setOpaque(false);
|
||||
|
||||
// Board
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = 1;
|
||||
gbc.fill = GridBagConstraints.BOTH;
|
||||
chessPanel.add(boardPanel(), gbc);
|
||||
// Toolbar Schwarz (oben)
|
||||
JPanel blackToolbar = toolbarPanel(false);
|
||||
boardAndToolbars.add(blackToolbar, BorderLayout.NORTH);
|
||||
|
||||
// Toolbar unten
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = 2;
|
||||
gbc.fill = GridBagConstraints.HORIZONTAL;
|
||||
chessPanel.add(toolbarPanel(true), gbc);
|
||||
// Board (zentriert im Panel)
|
||||
JPanel board = boardPanel();
|
||||
boardAndToolbars.add(board, BorderLayout.CENTER);
|
||||
|
||||
// Drehknopf
|
||||
flipBoardButton = new JButton("⇵");
|
||||
flipBoardButton.setPreferredSize(new Dimension(70, 70));
|
||||
flipBoardButton.setFont(new Font("SansSerif", Font.BOLD, 40));
|
||||
flipBoardButton.setBackground(new Color(0x5500ff));
|
||||
flipBoardButton.setForeground(Color.WHITE);
|
||||
flipBoardButton.setFocusPainted(false);
|
||||
// Toolbar Weiß (unten)
|
||||
JPanel whiteToolbar = toolbarPanel(true);
|
||||
boardAndToolbars.add(whiteToolbar, BorderLayout.SOUTH);
|
||||
|
||||
// Board+Toolbars mittig in einem Panel mit FlowLayout, damit sie zentriert sind
|
||||
JPanel centerPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));
|
||||
centerPanel.setOpaque(false);
|
||||
centerPanel.add(boardAndToolbars);
|
||||
|
||||
GridBagConstraints btn = new GridBagConstraints();
|
||||
btn.gridx = 0;
|
||||
btn.gridy = 2;
|
||||
btn.weightx = 0.0;
|
||||
btn.weighty = 0.0;
|
||||
btn.anchor = GridBagConstraints.EAST;
|
||||
btn.insets = new Insets(5, 0, 0, 0);
|
||||
chessPanel.add(flipBoardButton, btn);
|
||||
blackToolbar.setPreferredSize(new Dimension(0, 70)); // 70 px hoch
|
||||
whiteToolbar.setPreferredSize(new Dimension(0, 70));
|
||||
// Dynamisch skalieren wie gehabt
|
||||
centerPanel.addComponentListener(new java.awt.event.ComponentAdapter() {
|
||||
public void componentResized(java.awt.event.ComponentEvent evt) {
|
||||
int totalHeight = centerPanel.getHeight();
|
||||
int totalWidth = centerPanel.getWidth();
|
||||
int toolbarHeight = blackToolbar.getPreferredSize().height + whiteToolbar.getPreferredSize().height;
|
||||
// Falls Toolbars keine PrefSize haben, nimm getHeight()
|
||||
if (toolbarHeight == 0) toolbarHeight = blackToolbar.getHeight() + whiteToolbar.getHeight();
|
||||
int boardMaxHeight = totalHeight - toolbarHeight;
|
||||
int size = Math.min(totalWidth, boardMaxHeight);
|
||||
board.setPreferredSize(new Dimension(size, size));
|
||||
board.revalidate();
|
||||
}
|
||||
});
|
||||
|
||||
chessPanel.add(centerPanel, BorderLayout.CENTER);
|
||||
|
||||
// Drehknopf rechts, schön mittig
|
||||
JPanel eastPanel = new JPanel();
|
||||
eastPanel.setOpaque(false);
|
||||
eastPanel.setLayout(new BoxLayout(eastPanel, BoxLayout.Y_AXIS));
|
||||
eastPanel.add(Box.createVerticalGlue());
|
||||
eastPanel.add(flipBoardButton = createFlipButton());
|
||||
eastPanel.add(Box.createVerticalGlue());
|
||||
chessPanel.add(eastPanel, BorderLayout.EAST);
|
||||
|
||||
// Buffer links, wenn du willst
|
||||
chessPanel.add(Box.createRigidArea(new Dimension(40, 0)), BorderLayout.WEST);
|
||||
|
||||
return chessPanel;
|
||||
}
|
||||
|
||||
|
||||
// Flip-Knopf Builder, damit du’s an mehreren Stellen nutzen kannst:
|
||||
private JButton createFlipButton() {
|
||||
JButton btn = new JButton("⇵");
|
||||
btn.setPreferredSize(new Dimension(70, 70));
|
||||
btn.setFont(new Font("SansSerif", Font.BOLD, 40));
|
||||
btn.setBackground(new Color(0x5500ff));
|
||||
btn.setForeground(Color.WHITE);
|
||||
btn.setFocusPainted(false);
|
||||
return btn;
|
||||
}
|
||||
|
||||
|
||||
private JPanel fenPanel() {
|
||||
JPanel panel = new JPanel();
|
||||
|
|
@ -160,7 +209,21 @@ public class CreativeGui {
|
|||
updateBtn = new JButton("Update Board");
|
||||
updateBtn.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||
panel.add(updateBtn);
|
||||
|
||||
startGameButton = new JButton("🟢 Partie starten");
|
||||
startGameButton.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||
startGameButton.setBackground(new Color(0x218838));
|
||||
startGameButton.setForeground(Color.WHITE);
|
||||
panel.add(startGameButton);
|
||||
|
||||
startGameButton.addActionListener(e -> {
|
||||
if (startGameCallback != null) {
|
||||
setClosedByUser(false);
|
||||
startGameCallback.onStartGame(getFenText());
|
||||
}
|
||||
});
|
||||
return panel;
|
||||
|
||||
}
|
||||
|
||||
// Für Controller
|
||||
|
|
@ -171,8 +234,21 @@ public class CreativeGui {
|
|||
public JButton getUpdateButton() { return updateBtn; }
|
||||
public void setSelectedPiece(String piece) { selectedPiece = piece; }
|
||||
public String getSelectedPiece() { return selectedPiece; }
|
||||
public void setClosedByUser(boolean b) {
|
||||
this.closedByUser = b;
|
||||
}
|
||||
|
||||
public JButton getStartGameButton() { return startGameButton; }
|
||||
|
||||
public void setStartGameCallback(StartGameCallback callback) {
|
||||
this.startGameCallback = callback;
|
||||
}
|
||||
|
||||
public boolean isFlipped() { return isFlipped; }
|
||||
public void setFlipped(boolean f) { isFlipped = f; }
|
||||
public JButton getFlipBoardButton() { return flipBoardButton; }
|
||||
|
||||
public void close() {
|
||||
frame.dispose();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -238,6 +238,7 @@ public class GameGui {
|
|||
btnNext.setBackground(new Color(0x212529)); btnNext.setForeground(Color.WHITE);
|
||||
btnLast.setBackground(new Color(0x212529)); btnLast.setForeground(Color.WHITE);
|
||||
btnSave.setBackground(new Color(0x218838)); btnSave.setForeground(Color.WHITE);
|
||||
|
||||
buttonPanel.add(btnFirst);
|
||||
buttonPanel.add(btnPrev);
|
||||
buttonPanel.add(btnNext);
|
||||
|
|
@ -253,8 +254,8 @@ public class GameGui {
|
|||
JPanel panel = new JPanel(new GridLayout(2, 1));
|
||||
panel.setBackground(new Color(0x0d1b2a));
|
||||
|
||||
whiteTimerLabel = new JLabel("Weiß: 03:00", SwingConstants.CENTER);
|
||||
blackTimerLabel = new JLabel("Schwarz: 03:00", SwingConstants.CENTER);
|
||||
whiteTimerLabel = new JLabel("Weiß: --:--", SwingConstants.CENTER);
|
||||
blackTimerLabel = new JLabel("Schwarz: --:--", SwingConstants.CENTER);
|
||||
|
||||
whiteTimerLabel.setFont(new Font("SansSerif", Font.BOLD, 24));
|
||||
whiteTimerLabel.setForeground(Color.WHITE);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
package de.hs_mannheim.informatik.chess.view;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import de.hs_mannheim.informatik.chess.model.GameMode;
|
||||
|
||||
public class GameModeSelector {
|
||||
|
||||
public static GameMode selectGameMode() {
|
||||
GameMode[] options = GameMode.values();
|
||||
GameMode selected = (GameMode) JOptionPane.showInputDialog(
|
||||
null,
|
||||
"Wähle den Spielmodus:",
|
||||
"Spielmodus auswählen",
|
||||
JOptionPane.QUESTION_MESSAGE,
|
||||
null,
|
||||
options,
|
||||
GameMode.CLASSIC
|
||||
);
|
||||
|
||||
return selected != null ? selected : GameMode.CLASSIC;
|
||||
}
|
||||
}
|
||||
|
|
@ -3,6 +3,7 @@ package de.hs_mannheim.informatik.chess.view;
|
|||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Font;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
|
|
@ -10,6 +11,7 @@ import java.awt.GridLayout;
|
|||
import java.awt.Insets;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.Box;
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
|
|
@ -33,6 +35,8 @@ public class PgnGui {
|
|||
JButton btnNext = new JButton(">");
|
||||
JButton btnLast = new JButton(">|");
|
||||
|
||||
private JLabel openingLabel;
|
||||
|
||||
Color LIGHT = new Color(0xe0e1dd);
|
||||
Color DARK = new Color(0x778da9);
|
||||
|
||||
|
|
@ -54,6 +58,12 @@ public class PgnGui {
|
|||
|
||||
frame.setDefaultCloseOperation(2);
|
||||
frame.setVisible(true);
|
||||
frame.addWindowListener(new java.awt.event.WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosed(java.awt.event.WindowEvent e) {
|
||||
new de.hs_mannheim.informatik.chess.controller.MainController();
|
||||
}
|
||||
});
|
||||
return frame;
|
||||
}
|
||||
|
||||
|
|
@ -124,37 +134,57 @@ public class PgnGui {
|
|||
return boardPanel;
|
||||
}
|
||||
|
||||
public JPanel chessPanel(JPanel panel) {
|
||||
JPanel chessPanel = new JPanel(new GridBagLayout());
|
||||
GridBagConstraints board = new GridBagConstraints();
|
||||
chessPanel.setBackground(new Color(0x1b263b));
|
||||
board.gridx = 0;
|
||||
board.gridy = 0;
|
||||
board.weightx = 0.7;
|
||||
board.weighty = 1.0;
|
||||
board.insets = new Insets(0, 0, 0, 0);
|
||||
//oben, links, unten, rechts
|
||||
board.fill = GridBagConstraints.BOTH;
|
||||
chessPanel.add(panel);
|
||||
// Button unten rechts
|
||||
flipBoardButton = new JButton("⇵");
|
||||
flipBoardButton.setPreferredSize(new Dimension(70, 70));
|
||||
flipBoardButton.setFont(new Font("SansSerif", Font.BOLD, 40));
|
||||
flipBoardButton.setBackground(new Color(0x5500ff));
|
||||
flipBoardButton.setForeground(Color.WHITE);
|
||||
flipBoardButton.setFocusPainted(false);
|
||||
public JPanel chessPanel(JPanel boardPanel) {
|
||||
JPanel chessPanel = new JPanel(new BorderLayout());
|
||||
chessPanel.setBackground(new Color(0x1b263b));
|
||||
|
||||
GridBagConstraints btn = new GridBagConstraints();
|
||||
btn.gridx = 0;
|
||||
btn.gridy = 1;
|
||||
btn.weightx = 0.0;
|
||||
btn.weighty = 0.0;
|
||||
btn.anchor = GridBagConstraints.SOUTHEAST;
|
||||
btn.insets = new Insets(10, 0, 0, 0);
|
||||
// --- Eröffnungslabel oben ---
|
||||
openingLabel = new JLabel("Eröffnung: unbekannt", SwingConstants.CENTER);
|
||||
openingLabel.setFont(new Font("SansSerif", Font.BOLD, 24));
|
||||
openingLabel.setForeground(Color.WHITE);
|
||||
openingLabel.setOpaque(true);
|
||||
openingLabel.setBackground(new Color(0x283655));
|
||||
openingLabel.setPreferredSize(new Dimension(800, 50));
|
||||
chessPanel.add(openingLabel, BorderLayout.NORTH);
|
||||
|
||||
chessPanel.add(flipBoardButton, btn);
|
||||
|
||||
return chessPanel;
|
||||
// --- Board in ein zentriertes Panel mit fixer Größe ---
|
||||
JPanel centerPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));
|
||||
centerPanel.setOpaque(false);
|
||||
centerPanel.add(boardPanel);
|
||||
|
||||
centerPanel.addComponentListener(new java.awt.event.ComponentAdapter() {
|
||||
public void componentResized(java.awt.event.ComponentEvent evt) {
|
||||
int size = Math.min(centerPanel.getWidth(), centerPanel.getHeight());
|
||||
boardPanel.setPreferredSize(new Dimension(size, size));
|
||||
boardPanel.revalidate();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
chessPanel.add(centerPanel, BorderLayout.CENTER);
|
||||
|
||||
// --- Dummy-Buffer für WEST und EAST ---
|
||||
chessPanel.add(Box.createRigidArea(new Dimension(40, 0)), BorderLayout.WEST);
|
||||
chessPanel.add(Box.createRigidArea(new Dimension(40, 0)), BorderLayout.EAST);
|
||||
|
||||
// --- Buttonleiste unten bauen ---
|
||||
JPanel buttonRow = new JPanel();
|
||||
buttonRow.setOpaque(false);
|
||||
buttonRow.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT, 10, 0));
|
||||
|
||||
|
||||
flipBoardButton = new JButton("⇵");
|
||||
flipBoardButton.setPreferredSize(new Dimension(70, 70));
|
||||
flipBoardButton.setFont(new Font("SansSerif", Font.BOLD, 40));
|
||||
flipBoardButton.setBackground(new Color(0x5500ff));
|
||||
flipBoardButton.setForeground(Color.WHITE);
|
||||
flipBoardButton.setFocusPainted(false);
|
||||
|
||||
buttonRow.add(flipBoardButton);
|
||||
|
||||
chessPanel.add(buttonRow, BorderLayout.SOUTH);
|
||||
|
||||
return chessPanel;
|
||||
}
|
||||
|
||||
public JPanel statsPanel() {
|
||||
|
|
@ -240,6 +270,11 @@ public class PgnGui {
|
|||
this.isFlipped = flipped;
|
||||
}
|
||||
|
||||
public void setOpeningLabel(String text) {
|
||||
openingLabel.setText("Eröffnung: " + text);
|
||||
}
|
||||
|
||||
|
||||
public JButton getBtnFirst() { return btnFirst; }
|
||||
public JButton getBtnPrev() { return btnPrev; }
|
||||
public JButton getBtnNext() { return btnNext; }
|
||||
|
|
|
|||
Loading…
Reference in New Issue