changes to classes
parent
8447ce5fe3
commit
4cee12cfb9
|
|
@ -31,10 +31,21 @@ public class ChessEngine {
|
||||||
private int currentMoveIndex = 0;
|
private int currentMoveIndex = 0;
|
||||||
private Timer whiteTimer;
|
private Timer whiteTimer;
|
||||||
private Timer blackTimer;
|
private Timer blackTimer;
|
||||||
|
private final GameMode mode;
|
||||||
|
|
||||||
|
|
||||||
private Opening detectedOpening = null;
|
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();
|
logging();
|
||||||
board = new Board();
|
board = new Board();
|
||||||
}
|
}
|
||||||
|
|
@ -412,6 +423,17 @@ public class ChessEngine {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Timer getWhiteTimer() { return whiteTimer; }
|
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";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -19,6 +19,8 @@ public class CreativeGui {
|
||||||
private JButton updateBtn;
|
private JButton updateBtn;
|
||||||
private JButton flipBoardButton;
|
private JButton flipBoardButton;
|
||||||
|
|
||||||
|
private boolean closedByUser = true;
|
||||||
|
|
||||||
private StartGameCallback startGameCallback;
|
private StartGameCallback startGameCallback;
|
||||||
|
|
||||||
private JButton startGameButton;
|
private JButton startGameButton;
|
||||||
|
|
@ -65,6 +67,15 @@ public class CreativeGui {
|
||||||
gbc.fill = GridBagConstraints.BOTH;
|
gbc.fill = GridBagConstraints.BOTH;
|
||||||
mainPanel.add(fenPanel(), gbc);
|
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.setContentPane(mainPanel);
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
@ -207,6 +218,7 @@ public class CreativeGui {
|
||||||
|
|
||||||
startGameButton.addActionListener(e -> {
|
startGameButton.addActionListener(e -> {
|
||||||
if (startGameCallback != null) {
|
if (startGameCallback != null) {
|
||||||
|
setClosedByUser(false);
|
||||||
startGameCallback.onStartGame(getFenText());
|
startGameCallback.onStartGame(getFenText());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -222,6 +234,9 @@ public class CreativeGui {
|
||||||
public JButton getUpdateButton() { return updateBtn; }
|
public JButton getUpdateButton() { return updateBtn; }
|
||||||
public void setSelectedPiece(String piece) { selectedPiece = piece; }
|
public void setSelectedPiece(String piece) { selectedPiece = piece; }
|
||||||
public String getSelectedPiece() { return selectedPiece; }
|
public String getSelectedPiece() { return selectedPiece; }
|
||||||
|
public void setClosedByUser(boolean b) {
|
||||||
|
this.closedByUser = b;
|
||||||
|
}
|
||||||
|
|
||||||
public JButton getStartGameButton() { return startGameButton; }
|
public JButton getStartGameButton() { return startGameButton; }
|
||||||
|
|
||||||
|
|
@ -232,4 +247,8 @@ public class CreativeGui {
|
||||||
public boolean isFlipped() { return isFlipped; }
|
public boolean isFlipped() { return isFlipped; }
|
||||||
public void setFlipped(boolean f) { isFlipped = f; }
|
public void setFlipped(boolean f) { isFlipped = f; }
|
||||||
public JButton getFlipBoardButton() { return flipBoardButton; }
|
public JButton getFlipBoardButton() { return flipBoardButton; }
|
||||||
|
|
||||||
|
public void close() {
|
||||||
|
frame.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -254,8 +254,8 @@ public class GameGui {
|
||||||
JPanel panel = new JPanel(new GridLayout(2, 1));
|
JPanel panel = new JPanel(new GridLayout(2, 1));
|
||||||
panel.setBackground(new Color(0x0d1b2a));
|
panel.setBackground(new Color(0x0d1b2a));
|
||||||
|
|
||||||
whiteTimerLabel = new JLabel("Weiß: 03:00", SwingConstants.CENTER);
|
whiteTimerLabel = new JLabel("Weiß: --:--", SwingConstants.CENTER);
|
||||||
blackTimerLabel = new JLabel("Schwarz: 03:00", SwingConstants.CENTER);
|
blackTimerLabel = new JLabel("Schwarz: --:--", SwingConstants.CENTER);
|
||||||
|
|
||||||
whiteTimerLabel.setFont(new Font("SansSerif", Font.BOLD, 24));
|
whiteTimerLabel.setFont(new Font("SansSerif", Font.BOLD, 24));
|
||||||
whiteTimerLabel.setForeground(Color.WHITE);
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue