Compare commits
No commits in common. "9df9d5bbe9225e53095bbff7f4fe125a6591b946" and "8447ce5fe3ac05132e797591e8f0d168f1cf4bbb" have entirely different histories.
9df9d5bbe9
...
8447ce5fe3
|
|
@ -11,12 +11,11 @@ import javax.swing.BorderFactory;
|
||||||
import com.github.bhlangonijr.chesslib.game.Game;
|
import com.github.bhlangonijr.chesslib.game.Game;
|
||||||
|
|
||||||
import de.hs_mannheim.informatik.chess.model.ChessEngine;
|
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.MoveDTO;
|
||||||
import de.hs_mannheim.informatik.chess.model.PieceDTO;
|
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.model.BoardDTO;
|
||||||
import de.hs_mannheim.informatik.chess.view.GameGui;
|
import de.hs_mannheim.informatik.chess.view.GameGui;
|
||||||
|
import de.hs_mannheim.informatik.chess.view.MainGui;
|
||||||
|
|
||||||
public class GameController {
|
public class GameController {
|
||||||
GameGui gui;
|
GameGui gui;
|
||||||
|
|
@ -26,25 +25,12 @@ public class GameController {
|
||||||
private boolean gameOver = false;
|
private boolean gameOver = false;
|
||||||
private int selectedRow = -1, selectedCol = -1;
|
private int selectedRow = -1, selectedCol = -1;
|
||||||
private List<int[]> highlightedFields = new ArrayList<>();
|
private List<int[]> highlightedFields = new ArrayList<>();
|
||||||
private GameMode gameMode;
|
|
||||||
|
|
||||||
public GameController(GameGui gui, ChessEngine engine, GameEndCallback callback) {
|
public GameController(GameGui gui, ChessEngine engine, GameEndCallback callback) {
|
||||||
this.gameMode = null;
|
|
||||||
this.gui = gui;
|
this.gui = gui;
|
||||||
this.engine = engine;
|
this.engine = engine;
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
engine.initTimers(gameMode.minutes, gameMode.incrementSeconds);
|
engine.initTimers(3, 0);
|
||||||
time();
|
|
||||||
initListeners();
|
|
||||||
updateGuiBoard();
|
|
||||||
}
|
|
||||||
|
|
||||||
public GameController(GameGui gui, ChessEngine engine, GameEndCallback callback, GameMode gameMode) {
|
|
||||||
this.gameMode = gameMode;
|
|
||||||
this.gui = gui;
|
|
||||||
this.engine = engine;
|
|
||||||
this.callback = callback;
|
|
||||||
engine.initTimers(gameMode.minutes, gameMode.incrementSeconds);
|
|
||||||
time();
|
time();
|
||||||
initListeners();
|
initListeners();
|
||||||
updateGuiBoard();
|
updateGuiBoard();
|
||||||
|
|
@ -294,8 +280,6 @@ public class GameController {
|
||||||
updateGuiBoard();
|
updateGuiBoard();
|
||||||
gui.updateMoveList(engine.getMoveListStringsGrouped());
|
gui.updateMoveList(engine.getMoveListStringsGrouped());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ---- HIER ist die Matt/Patt/Remis-Prüfung ----
|
// ---- HIER ist die Matt/Patt/Remis-Prüfung ----
|
||||||
if (engine.isMated()) {
|
if (engine.isMated()) {
|
||||||
String winner = engine.getCurrentPlayer().equals("WHITE") ? "SCHWARZ" : "WEIß";
|
String winner = engine.getCurrentPlayer().equals("WHITE") ? "SCHWARZ" : "WEIß";
|
||||||
|
|
@ -321,26 +305,13 @@ public class GameController {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void switchTimers() {
|
private void switchTimers() {
|
||||||
GameMode mode = engine.getGameMode(); // muss Engine speichern
|
|
||||||
Timer whiteTimer = engine.getWhiteTimer();
|
|
||||||
Timer blackTimer = engine.getBlackTimer();
|
|
||||||
|
|
||||||
if (engine.getCurrentPlayer().equals("WHITE")) {
|
if (engine.getCurrentPlayer().equals("WHITE")) {
|
||||||
// Der letzte Spieler war Schwarz – ihm ggf. Inkrement geben
|
engine.getBlackTimer().stop();
|
||||||
if (mode.incrementSeconds > 0) {
|
engine.getWhiteTimer().start();
|
||||||
blackTimer.addSeconds(mode.incrementSeconds);
|
|
||||||
}
|
|
||||||
blackTimer.stop();
|
|
||||||
whiteTimer.start();
|
|
||||||
} else {
|
} else {
|
||||||
// Der letzte Spieler war Weiß – ihm ggf. Inkrement geben
|
engine.getWhiteTimer().stop();
|
||||||
if (mode.incrementSeconds > 0) {
|
engine.getBlackTimer().start();
|
||||||
whiteTimer.addSeconds(mode.incrementSeconds);
|
|
||||||
}
|
}
|
||||||
whiteTimer.stop();
|
|
||||||
blackTimer.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ import de.hs_mannheim.informatik.chess.view.PgnGui;
|
||||||
import de.hs_mannheim.informatik.chess.view.PgnSelectionGui;
|
import de.hs_mannheim.informatik.chess.view.PgnSelectionGui;
|
||||||
import de.hs_mannheim.informatik.chess.view.CreativeGui;
|
import de.hs_mannheim.informatik.chess.view.CreativeGui;
|
||||||
import de.hs_mannheim.informatik.chess.view.GameGui;
|
import de.hs_mannheim.informatik.chess.view.GameGui;
|
||||||
import de.hs_mannheim.informatik.chess.view.GameModeSelector;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -16,7 +15,6 @@ import javax.swing.JOptionPane;
|
||||||
import com.github.bhlangonijr.chesslib.game.Game;
|
import com.github.bhlangonijr.chesslib.game.Game;
|
||||||
|
|
||||||
import de.hs_mannheim.informatik.chess.model.ChessEngine;
|
import de.hs_mannheim.informatik.chess.model.ChessEngine;
|
||||||
import de.hs_mannheim.informatik.chess.model.GameMode;
|
|
||||||
|
|
||||||
public class MainController {
|
public class MainController {
|
||||||
private MainGui mainGui;
|
private MainGui mainGui;
|
||||||
|
|
@ -30,11 +28,9 @@ public class MainController {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startNormalMode() {
|
private void startNormalMode() {
|
||||||
|
|
||||||
GameMode mode = GameModeSelector.selectGameMode();
|
|
||||||
mainGui.close();
|
mainGui.close();
|
||||||
GameGui gameGui = new GameGui();
|
GameGui gameGui = new GameGui();
|
||||||
ChessEngine engine = new ChessEngine(mode);
|
ChessEngine engine = new ChessEngine();
|
||||||
GameEndCallback callback = new GameEndCallback() {
|
GameEndCallback callback = new GameEndCallback() {
|
||||||
public void onNewGameRequested() {
|
public void onNewGameRequested() {
|
||||||
startNormalMode();
|
startNormalMode();
|
||||||
|
|
@ -43,7 +39,7 @@ public class MainController {
|
||||||
new MainController();
|
new MainController();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
new GameController(gameGui, engine, callback,mode);
|
new GameController(gameGui, engine, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startCreativeMode() {
|
private void startCreativeMode() {
|
||||||
|
|
|
||||||
|
|
@ -31,21 +31,10 @@ 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();
|
||||||
}
|
}
|
||||||
|
|
@ -423,17 +412,6 @@ 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,26 +0,0 @@
|
||||||
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,10 +56,6 @@ public class Timer {
|
||||||
public int getSecondsLeft() {
|
public int getSecondsLeft() {
|
||||||
return secondsLeft;
|
return secondsLeft;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addSeconds(int seconds) {
|
|
||||||
this.secondsLeft += seconds;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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ß: --:--", SwingConstants.CENTER);
|
whiteTimerLabel = new JLabel("Weiß: 03:00", SwingConstants.CENTER);
|
||||||
blackTimerLabel = new JLabel("Schwarz: --:--", SwingConstants.CENTER);
|
blackTimerLabel = new JLabel("Schwarz: 03:00", 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);
|
||||||
|
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
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