changes to classes

DevBranch
Justin 2025-06-24 04:01:13 +02:00
parent 8447ce5fe3
commit 4cee12cfb9
5 changed files with 96 additions and 6 deletions

View File

@ -31,13 +31,24 @@ public class ChessEngine {
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());
@ -264,7 +275,7 @@ public class ChessEngine {
logger.info("ChessEngine wurde initialisiert.");
}
public List<Game> loadGamesFromPgn(String path) throws IOException {
PgnHolder pgnHolder = new PgnHolder(path);
@ -412,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;
}
}

View File

@ -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";
};
}
}

View File

@ -19,6 +19,8 @@ public class CreativeGui {
private JButton updateBtn;
private JButton flipBoardButton;
private boolean closedByUser = true;
private StartGameCallback startGameCallback;
private JButton startGameButton;
@ -64,7 +66,16 @@ public class CreativeGui {
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);
}
@ -207,6 +218,7 @@ public class CreativeGui {
startGameButton.addActionListener(e -> {
if (startGameCallback != null) {
setClosedByUser(false);
startGameCallback.onStartGame(getFenText());
}
});
@ -222,6 +234,9 @@ 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; }
@ -232,4 +247,8 @@ public class CreativeGui {
public boolean isFlipped() { return isFlipped; }
public void setFlipped(boolean f) { isFlipped = f; }
public JButton getFlipBoardButton() { return flipBoardButton; }
public void close() {
frame.dispose();
}
}

View File

@ -254,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);

View File

@ -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;
}
}