Implemented the pgn reading feature in MainController
parent
6bd35f8e30
commit
b3af81910a
|
@ -2,8 +2,18 @@ package de.hs_mannheim.informatik.chess.controller;
|
|||
|
||||
import de.hs_mannheim.informatik.chess.view.MainGui;
|
||||
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 java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import com.github.bhlangonijr.chesslib.game.Game;
|
||||
|
||||
import de.hs_mannheim.informatik.chess.model.ChessEngine;
|
||||
|
||||
public class MainController {
|
||||
|
@ -32,9 +42,23 @@ public class MainController {
|
|||
}
|
||||
|
||||
private void startLoadGameMode() {
|
||||
mainGui.close();
|
||||
PgnGui pgngui = new PgnGui();
|
||||
ChessEngine engine = new ChessEngine();
|
||||
new PgnController(pgngui, engine);
|
||||
JFileChooser chooser = new JFileChooser();
|
||||
int result = chooser.showOpenDialog(null);
|
||||
if (result == JFileChooser.APPROVE_OPTION) {
|
||||
String path = chooser.getSelectedFile().getAbsolutePath();
|
||||
ChessEngine engine = new ChessEngine();
|
||||
try {
|
||||
List<Game> games = engine.loadGamesFromPgn(path);
|
||||
// Jetzt Auswahl-GUI öffnen!
|
||||
new PgnSelectionGui(games, selectedGame -> {
|
||||
// Callback wenn User eins ausgewählt hat!
|
||||
PgnGui pgnGui = new PgnGui();
|
||||
engine.loadMoves(selectedGame.getHalfMoves());
|
||||
new PgnController(pgnGui, engine);
|
||||
});
|
||||
} catch (IOException ex) {
|
||||
JOptionPane.showMessageDialog(null, "Fehler beim Laden der PGN-Datei:\n" + ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue