Das Game kann jetzt die einzelnen Spiele starten
parent
8e45acb0b3
commit
57b68bb0d2
|
@ -246,4 +246,19 @@ public class ChessEngine {
|
|||
}
|
||||
}
|
||||
|
||||
public void loadMoves(List<Move> moveList) {
|
||||
board = new Board(); // Neues leeres Brett
|
||||
moves.clear();
|
||||
currentMoveIndex = 0;
|
||||
|
||||
for (Move move : moveList) {
|
||||
board.doMove(move);
|
||||
moves.add(move);
|
||||
currentMoveIndex++;
|
||||
}
|
||||
|
||||
// Kein setPositionToMoveIndex() hier aufrufen!
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,19 +1,14 @@
|
|||
package de.hs_mannheim.informatik.chess.view;
|
||||
import de.hs_mannheim.informatik.chess.model.ChessEngine;
|
||||
import com.github.bhlangonijr.chesslib.game.Game;
|
||||
import java.util.List;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.Insets;
|
||||
import java.awt.Cursor;
|
||||
|
||||
import java.io.IOException;
|
||||
import com.github.bhlangonijr.chesslib.game.Game;
|
||||
import com.github.bhlangonijr.chesslib.move.Move;
|
||||
import de.hs_mannheim.informatik.chess.controller.Controller;
|
||||
import de.hs_mannheim.informatik.chess.model.ChessEngine;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public class MainGui {
|
||||
|
||||
|
@ -22,14 +17,13 @@ public class MainGui {
|
|||
private ChessEngine engine = new ChessEngine();
|
||||
|
||||
public MainGui(Runnable onStartGame) {
|
||||
this.onStartGame = onStartGame;
|
||||
this.onStartGame = onStartGame;
|
||||
|
||||
frame = new JFrame("Chess - Hauptmenü");
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.setSize(1600, 1000);
|
||||
frame.setLocationRelativeTo(null);
|
||||
|
||||
//Haupt-Panel mit GridBagLayout
|
||||
JPanel mainPanel = new JPanel(new GridBagLayout());
|
||||
mainPanel.setBackground(new Color(0xe0e1dd));
|
||||
|
||||
|
@ -38,7 +32,6 @@ public class MainGui {
|
|||
gbc.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc.insets = new Insets(15, 0, 15, 0);
|
||||
|
||||
//Title
|
||||
JLabel title = new JLabel("ChessDE", SwingConstants.CENTER);
|
||||
title.setFont(new Font("Serif", Font.BOLD, 150));
|
||||
title.setForeground(new Color(0x1b263b));
|
||||
|
@ -46,12 +39,10 @@ public class MainGui {
|
|||
gbc.ipady = 50;
|
||||
mainPanel.add(title, gbc);
|
||||
|
||||
//Abstand nach unten
|
||||
gbc.gridy = 1;
|
||||
gbc.ipady = 15;
|
||||
mainPanel.add(Box.createRigidArea(new Dimension(0, 20)), gbc);
|
||||
|
||||
//Buttons
|
||||
JButton btnMode1 = new JButton("Normal Mode");
|
||||
JButton btnMode2 = new JButton("Mode 2 (coming soon)");
|
||||
JButton btnMode3 = new JButton("Mode 3 (coming soon)");
|
||||
|
@ -82,10 +73,9 @@ public class MainGui {
|
|||
frame.add(mainPanel);
|
||||
frame.setVisible(true);
|
||||
|
||||
//Button ActionListener für "Normal Modus"
|
||||
btnMode1.addActionListener(e -> {
|
||||
frame.dispose(); // Hauptmenü schließen
|
||||
onStartGame.run(); // **Ruft den Callback auf**
|
||||
frame.dispose();
|
||||
onStartGame.run();
|
||||
});
|
||||
|
||||
btnLoadGame.addActionListener(e -> {
|
||||
|
@ -102,7 +92,6 @@ public class MainGui {
|
|||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void zeigeGeladeneSpiele(List<Game> games) {
|
||||
|
@ -123,10 +112,15 @@ public class MainGui {
|
|||
JButton gameButton = new JButton(title);
|
||||
gameButton.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||
gameButton.addActionListener(e -> {
|
||||
System.out.println("Ausgewähltes Spiel:\n" + game);
|
||||
JOptionPane.showMessageDialog(gameListFrame,
|
||||
"Noch keine Replay-Ansicht.\n" +
|
||||
"Spiel: " + white + " vs. " + black);
|
||||
gameListFrame.dispose();
|
||||
|
||||
GameGui gui = new GameGui();
|
||||
ChessEngine engine = new ChessEngine();
|
||||
|
||||
engine.loadMoves(game.getHalfMoves());
|
||||
engine.setPositionToMoveIndex(engine.getMoveListSize()); // zeige Endstellung
|
||||
|
||||
new Controller(gui, engine);
|
||||
});
|
||||
|
||||
panel.add(Box.createRigidArea(new Dimension(0, 10)));
|
||||
|
@ -137,7 +131,6 @@ public class MainGui {
|
|||
gameListFrame.setVisible(true);
|
||||
}
|
||||
|
||||
// Helper für Button Styling
|
||||
private void styleButton(JButton btn) {
|
||||
btn.setFont(new Font("Serif", Font.BOLD, 30));
|
||||
btn.setBackground(new Color(0x778da9));
|
||||
|
|
Loading…
Reference in New Issue