commit
518ff09d45
|
|
@ -27,16 +27,22 @@ public class ButtonMovePieceListener implements ActionListener {
|
||||||
else
|
else
|
||||||
this.game.playMove(this.mv);
|
this.game.playMove(this.mv);
|
||||||
|
|
||||||
|
this.game.setViewPointer(this.game.getMoveList().size() - 1);
|
||||||
|
|
||||||
if (this.game.isDraw()) {
|
if (this.game.isDraw()) {
|
||||||
this.game.stopClock();
|
this.game.stopClock();
|
||||||
this.sf.setBoardMode(BoardMode.finished);
|
this.sf.setBoardMode(BoardMode.finished);
|
||||||
|
this.sf.enableControlPanelButtons();
|
||||||
this.sf.showDraw();
|
this.sf.showDraw();
|
||||||
} else if (this.game.isMate()) {
|
} else if (this.game.isMate()) {
|
||||||
this.game.stopClock();
|
this.game.stopClock();
|
||||||
this.sf.setBoardMode(BoardMode.finished);
|
this.sf.setBoardMode(BoardMode.finished);
|
||||||
|
this.sf.enableControlPanelButtons();
|
||||||
this.sf.showWin(game.getActivePlayer());
|
this.sf.showWin(game.getActivePlayer());
|
||||||
}
|
} else {
|
||||||
this.sf.setBoardMode(BoardMode.normal);
|
this.sf.setBoardMode(BoardMode.normal);
|
||||||
|
}
|
||||||
|
|
||||||
this.sf.setCursor(null);
|
this.sf.setCursor(null);
|
||||||
this.sf.erstelleBrett();
|
this.sf.erstelleBrett();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
package de.mannheim.th.chess.controller.controlPanel;
|
||||||
|
|
||||||
|
import de.mannheim.th.chess.ui.SpielFrame;
|
||||||
|
import de.mannheim.th.chess.domain.Game;
|
||||||
|
|
||||||
|
public abstract class BaseButtonViewListener {
|
||||||
|
protected SpielFrame sf;
|
||||||
|
protected Game game;
|
||||||
|
|
||||||
|
public BaseButtonViewListener(Game game, SpielFrame sf) {
|
||||||
|
this.sf = sf;
|
||||||
|
this.game = game;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads the gamestate and renders the board
|
||||||
|
*/
|
||||||
|
protected void updateView() {
|
||||||
|
this.game.loadView();
|
||||||
|
this.sf.setDefaultButtons();
|
||||||
|
this.sf.applyBoardButtons();
|
||||||
|
this.sf.ladeBrett();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
package de.mannheim.th.chess.controller.controlPanel;
|
||||||
|
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
import de.mannheim.th.chess.domain.Game;
|
||||||
|
import de.mannheim.th.chess.ui.SpielFrame;
|
||||||
|
|
||||||
|
public class ButtonQuickloadListener implements ActionListener {
|
||||||
|
private Game game;
|
||||||
|
private SpielFrame sf;
|
||||||
|
|
||||||
|
public ButtonQuickloadListener(Game game, SpielFrame sf) {
|
||||||
|
this.game = game;
|
||||||
|
this.sf = sf;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
this.game.quickload();
|
||||||
|
this.sf.erstelleBrett();
|
||||||
|
this.sf.aktualisiereAusgabe();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
package de.mannheim.th.chess.controller.controlPanel;
|
||||||
|
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
import de.mannheim.th.chess.domain.Game;
|
||||||
|
|
||||||
|
public class ButtonQuicksaveListener implements ActionListener {
|
||||||
|
private Game game;
|
||||||
|
|
||||||
|
public ButtonQuicksaveListener(Game game) {
|
||||||
|
this.game = game;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
this.game.quicksave();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
package de.mannheim.th.chess.controller.controlPanel;
|
||||||
|
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
import de.mannheim.th.chess.domain.Game;
|
||||||
|
import de.mannheim.th.chess.ui.SpielFrame;
|
||||||
|
|
||||||
|
public class ButtonViewBackListener extends BaseButtonViewListener implements ActionListener {
|
||||||
|
|
||||||
|
public ButtonViewBackListener(Game game, SpielFrame sf) {
|
||||||
|
super(game, sf);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if (this.game.getViewPointer() > 0) {
|
||||||
|
this.game.setViewPointer(this.game.getViewPointer() - 1);
|
||||||
|
updateView();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
package de.mannheim.th.chess.controller.controlPanel;
|
||||||
|
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
import de.mannheim.th.chess.domain.Game;
|
||||||
|
import de.mannheim.th.chess.ui.SpielFrame;
|
||||||
|
|
||||||
|
public class ButtonViewFirstListener extends BaseButtonViewListener implements ActionListener {
|
||||||
|
|
||||||
|
public ButtonViewFirstListener(Game game, SpielFrame sf) {
|
||||||
|
super(game, sf);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
this.game.setViewPointer(0);
|
||||||
|
updateView();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
package de.mannheim.th.chess.controller.controlPanel;
|
||||||
|
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
import de.mannheim.th.chess.domain.Game;
|
||||||
|
import de.mannheim.th.chess.ui.SpielFrame;
|
||||||
|
|
||||||
|
public class ButtonViewForwardListener extends BaseButtonViewListener implements ActionListener {
|
||||||
|
|
||||||
|
public ButtonViewForwardListener(Game game, SpielFrame sf) {
|
||||||
|
super(game, sf);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if (this.game.getMoveList().size() > this.game.getViewPointer()) {
|
||||||
|
this.game.setViewPointer(this.game.getViewPointer() + 1);
|
||||||
|
updateView();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
|
||||||
|
package de.mannheim.th.chess.controller.controlPanel;
|
||||||
|
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
import de.mannheim.th.chess.domain.Game;
|
||||||
|
import de.mannheim.th.chess.ui.SpielFrame;
|
||||||
|
|
||||||
|
public class ButtonViewLastListener extends BaseButtonViewListener implements ActionListener {
|
||||||
|
|
||||||
|
public ButtonViewLastListener(Game game, SpielFrame sf) {
|
||||||
|
super(game, sf);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
this.game.setViewPointer(this.game.getMoveList().size());
|
||||||
|
updateView();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -16,7 +16,6 @@ import com.github.bhlangonijr.chesslib.move.MoveList;
|
||||||
import com.github.bhlangonijr.chesslib.pgn.PgnHolder;
|
import com.github.bhlangonijr.chesslib.pgn.PgnHolder;
|
||||||
|
|
||||||
import de.mannheim.th.chess.App;
|
import de.mannheim.th.chess.App;
|
||||||
import de.mannheim.th.chess.ui.SpielFrame;
|
|
||||||
import de.mannheim.th.chess.utl.Clock;
|
import de.mannheim.th.chess.utl.Clock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -29,23 +28,28 @@ public class Game {
|
||||||
|
|
||||||
private Board board;
|
private Board board;
|
||||||
private Clock clock;
|
private Clock clock;
|
||||||
private SpielFrame sp;
|
|
||||||
private String modus;
|
private String modus;
|
||||||
private boolean rotieren, zuruecknahme;
|
private boolean rotieren, zuruecknahme;
|
||||||
|
|
||||||
private MoveList movelist;
|
private MoveList movelist;
|
||||||
|
private int viewPointer;
|
||||||
|
|
||||||
public Game() {
|
private MoveList savestate;
|
||||||
|
private String startPosFen;
|
||||||
this.board = new Board();
|
|
||||||
this.movelist = new MoveList();
|
|
||||||
clock = new Clock("blitz");
|
|
||||||
clock.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Conststructs a new standard GameBoard.
|
* Conststructs a new standard GameBoard.
|
||||||
*/
|
*/
|
||||||
|
public Game() {
|
||||||
|
|
||||||
|
this.board = new Board();
|
||||||
|
this.movelist = new MoveList();
|
||||||
|
this.startPosFen = this.board.getFen();
|
||||||
|
|
||||||
|
clock = new Clock("blitz");
|
||||||
|
clock.start();
|
||||||
|
}
|
||||||
|
|
||||||
public Game(String modus, boolean rotieren, boolean zuruecknahme, String fen) {
|
public Game(String modus, boolean rotieren, boolean zuruecknahme, String fen) {
|
||||||
this.modus = modus;
|
this.modus = modus;
|
||||||
this.rotieren = rotieren;
|
this.rotieren = rotieren;
|
||||||
|
|
@ -58,12 +62,10 @@ public class Game {
|
||||||
|
|
||||||
this.board.loadFromFen(fen);
|
this.board.loadFromFen(fen);
|
||||||
|
|
||||||
|
this.startPosFen = this.board.getFen();
|
||||||
this.movelist = new MoveList();
|
this.movelist = new MoveList();
|
||||||
|
|
||||||
clock = new Clock(modus);
|
clock = new Clock(modus);
|
||||||
|
|
||||||
sp = new SpielFrame(this);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -74,14 +76,14 @@ public class Game {
|
||||||
public Game(MoveList movelist) {
|
public Game(MoveList movelist) {
|
||||||
this.board = new Board();
|
this.board = new Board();
|
||||||
|
|
||||||
|
this.startPosFen = this.board.getFen();
|
||||||
this.movelist = movelist;
|
this.movelist = movelist;
|
||||||
|
|
||||||
for (Move move : movelist) {
|
for (Move move : movelist) {
|
||||||
this.board.doMove(move);
|
this.board.doMove(move);
|
||||||
}
|
}
|
||||||
|
|
||||||
// this.clockPlayer1 = new Clock();
|
this.clock = new Clock("blitz");
|
||||||
// this.clockPlayer2 = new Clock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -94,6 +96,7 @@ public class Game {
|
||||||
this.board.loadFromFen(fen);
|
this.board.loadFromFen(fen);
|
||||||
|
|
||||||
this.movelist = new MoveList();
|
this.movelist = new MoveList();
|
||||||
|
this.startPosFen = this.board.getFen();
|
||||||
// this.sp = new SpielFrame();
|
// this.sp = new SpielFrame();
|
||||||
|
|
||||||
// this.clockPlayer1 = new Clock();
|
// this.clockPlayer1 = new Clock();
|
||||||
|
|
@ -123,6 +126,37 @@ public class Game {
|
||||||
this.movelist.removeLast();
|
this.movelist.removeLast();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies the current move list to the savestate
|
||||||
|
*/
|
||||||
|
public void quicksave() {
|
||||||
|
// TODO: save the current clocktime
|
||||||
|
this.savestate = new MoveList(this.movelist);
|
||||||
|
|
||||||
|
logger.info("Quicksaved...");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads the save state
|
||||||
|
*
|
||||||
|
* @brief creates a new board with the startPosFen and then plays all the moves
|
||||||
|
* from the savestate
|
||||||
|
*/
|
||||||
|
public void quickload() {
|
||||||
|
if (this.savestate != null) {
|
||||||
|
|
||||||
|
this.board = new Board();
|
||||||
|
this.movelist.clear();
|
||||||
|
this.board.loadFromFen(startPosFen);
|
||||||
|
|
||||||
|
for (Move move : savestate) {
|
||||||
|
this.playMove(move);
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("Quickloaded...");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plays the move on the board and adds it to the movelist
|
* Plays the move on the board and adds it to the movelist
|
||||||
*
|
*
|
||||||
|
|
@ -272,11 +306,33 @@ public class Game {
|
||||||
return board.getFen();
|
return board.getFen();
|
||||||
}
|
}
|
||||||
|
|
||||||
// public Square getSelectedSquare() {
|
// public Square getSelectedSquare() {
|
||||||
// return this.getSelectedSquare();
|
// return this.getSelectedSquare();
|
||||||
// }
|
// }
|
||||||
|
|
||||||
public String getUnicodeFromMove(Move move) {
|
public String getUnicodeFromMove(Move move) {
|
||||||
return board.getPiece(move.getTo()).getFanSymbol().toUpperCase();
|
return board.getPiece(move.getTo()).getFanSymbol().toUpperCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setViewPointer(int i) {
|
||||||
|
this.viewPointer = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getViewPointer() {
|
||||||
|
return this.viewPointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads the current view
|
||||||
|
*
|
||||||
|
* @brief Creates a new gameboard from the start pos and playes moves until it
|
||||||
|
* reaches the viewPointer
|
||||||
|
*/
|
||||||
|
public void loadView() {
|
||||||
|
this.board = new Board();
|
||||||
|
this.board.loadFromFen(this.startPosFen);
|
||||||
|
for (int i = 0; i < this.viewPointer; i++) {
|
||||||
|
this.board.doMove(this.movelist.get(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import de.mannheim.th.chess.App;
|
import de.mannheim.th.chess.App;
|
||||||
|
import de.mannheim.th.chess.domain.Game;
|
||||||
|
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
|
|
||||||
|
|
@ -28,6 +29,7 @@ public class MainFrame extends JFrame {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
private JPanel contentPane;
|
private JPanel contentPane;
|
||||||
|
private Game game;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the frame.
|
* Create the frame.
|
||||||
|
|
@ -77,9 +79,7 @@ public class MainFrame extends JFrame {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
openSelectModeFrame();
|
||||||
ModeSelectionFrame ms = new ModeSelectionFrame();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
@ -87,6 +87,12 @@ public class MainFrame extends JFrame {
|
||||||
|
|
||||||
contentPane.add(Box.createVerticalStrut(15));
|
contentPane.add(Box.createVerticalStrut(15));
|
||||||
|
|
||||||
|
JButton pgnLoaderButton = new JButton("Lade aus PGN Datei");
|
||||||
|
pgnLoaderButton.addActionListener(e -> openPgnSelectFrame());
|
||||||
|
contentPane.add(pgnLoaderButton);
|
||||||
|
|
||||||
|
contentPane.add(Box.createVerticalStrut(15));
|
||||||
|
|
||||||
JButton btnNewButton_2 = new JButton("App beenden");
|
JButton btnNewButton_2 = new JButton("App beenden");
|
||||||
|
|
||||||
btnNewButton_2.setBackground(Color.LIGHT_GRAY);
|
btnNewButton_2.setBackground(Color.LIGHT_GRAY);
|
||||||
|
|
@ -105,4 +111,44 @@ public class MainFrame extends JFrame {
|
||||||
contentPane.add(btnNewButton_2);
|
contentPane.add(btnNewButton_2);
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts the spielframe and game in playmode
|
||||||
|
*/
|
||||||
|
public void startGame() {
|
||||||
|
if (this.game != null) {
|
||||||
|
this.game.stopClock();
|
||||||
|
SpielFrame sf = new SpielFrame(this.game);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts the spielframe and game in view mode
|
||||||
|
*/
|
||||||
|
public void startView() {
|
||||||
|
if (this.game != null) {
|
||||||
|
this.game.stopClock();
|
||||||
|
SpielFrame sf = new SpielFrame(this.game);
|
||||||
|
sf.setMode(SpielFrame.BoardMode.finished);
|
||||||
|
sf.enableControlPanelButtons();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGame(Game game) {
|
||||||
|
this.game = game;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* opens the selectmodeframe
|
||||||
|
*/
|
||||||
|
private void openSelectModeFrame() {
|
||||||
|
new ModeSelectionFrame(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opens the pgnselectorframe
|
||||||
|
*/
|
||||||
|
private void openPgnSelectFrame() {
|
||||||
|
new PGNLoaderFrame(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ public class ModeSelectionFrame extends JFrame {
|
||||||
private final ArrayList<Game> spiele = new ArrayList<>();
|
private final ArrayList<Game> spiele = new ArrayList<>();
|
||||||
private String fen;
|
private String fen;
|
||||||
|
|
||||||
public ModeSelectionFrame() {
|
public ModeSelectionFrame(MainFrame mf) {
|
||||||
// Frame-Eigenschaften
|
// Frame-Eigenschaften
|
||||||
setTitle("Modusauswahl");
|
setTitle("Modusauswahl");
|
||||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||||
|
|
@ -52,27 +52,27 @@ public class ModeSelectionFrame extends JFrame {
|
||||||
contentPane.add(Box.createVerticalStrut(15));
|
contentPane.add(Box.createVerticalStrut(15));
|
||||||
|
|
||||||
// Modusauswahl
|
// Modusauswahl
|
||||||
String[] modi = {"Blitz", "Schnellschach", "Klassisch"};
|
String[] modi = { "Blitz", "Schnellschach", "Klassisch" };
|
||||||
JComboBox<String> jcb1 = new JComboBox<>(modi);
|
JComboBox<String> jcb1 = new JComboBox<>(modi);
|
||||||
jcb1 .setMaximumSize(new Dimension(150, 30));
|
jcb1.setMaximumSize(new Dimension(150, 30));
|
||||||
jcb1 .setAlignmentX(Component.CENTER_ALIGNMENT);
|
jcb1.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||||
contentPane.add(jcb1 );
|
contentPane.add(jcb1);
|
||||||
contentPane.add(Box.createVerticalStrut(15));
|
contentPane.add(Box.createVerticalStrut(15));
|
||||||
|
|
||||||
// Spielbrettdrehen
|
// Spielbrettdrehen
|
||||||
JLabel jl2 = new JLabel("Soll das Spielbrett nach jedem Zug gedreht werden?");
|
JLabel jl2 = new JLabel("Soll das Spielbrett nach jedem Zug gedreht werden?");
|
||||||
jl2 .setFont(new Font("Calibri", Font.BOLD, 20));
|
jl2.setFont(new Font("Calibri", Font.BOLD, 20));
|
||||||
jl2 .setForeground(Color.BLACK);
|
jl2.setForeground(Color.BLACK);
|
||||||
jl2 .setAlignmentX(Component.CENTER_ALIGNMENT);
|
jl2.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||||
contentPane.add(jl2 );
|
contentPane.add(jl2);
|
||||||
|
|
||||||
JCheckBox jb1 = new JCheckBox();
|
JCheckBox jb1 = new JCheckBox();
|
||||||
jb1.setOpaque(false);
|
jb1.setOpaque(false);
|
||||||
jb1.setFocusPainted(false);
|
jb1.setFocusPainted(false);
|
||||||
jb1.setForeground(Color.BLACK);
|
jb1.setForeground(Color.BLACK);
|
||||||
jb1 .setAlignmentX(Component.CENTER_ALIGNMENT);
|
jb1.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||||
jb1 .setMaximumSize(new Dimension(30, 30));
|
jb1.setMaximumSize(new Dimension(30, 30));
|
||||||
contentPane.add(jb1 );
|
contentPane.add(jb1);
|
||||||
contentPane.add(Box.createVerticalStrut(15));
|
contentPane.add(Box.createVerticalStrut(15));
|
||||||
|
|
||||||
// Zurücknahmeoption
|
// Zurücknahmeoption
|
||||||
|
|
@ -106,14 +106,14 @@ public class ModeSelectionFrame extends JFrame {
|
||||||
|
|
||||||
// Spiel starten Button
|
// Spiel starten Button
|
||||||
JButton btnNewButton = new JButton("Spiel starten");
|
JButton btnNewButton = new JButton("Spiel starten");
|
||||||
btnNewButton .setBackground(Color.LIGHT_GRAY);
|
btnNewButton.setBackground(Color.LIGHT_GRAY);
|
||||||
btnNewButton .setForeground(Color.BLACK);
|
btnNewButton.setForeground(Color.BLACK);
|
||||||
btnNewButton .setFont(new Font("Tahoma", Font.BOLD, 16));
|
btnNewButton.setFont(new Font("Tahoma", Font.BOLD, 16));
|
||||||
btnNewButton .setAlignmentX(Component.CENTER_ALIGNMENT);
|
btnNewButton.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||||
contentPane.add(btnNewButton );
|
contentPane.add(btnNewButton);
|
||||||
|
|
||||||
// Button-Listener
|
// Button-Listener
|
||||||
btnNewButton .addActionListener(new ActionListener() {
|
btnNewButton.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
String modus = (String) jcb1.getSelectedItem();
|
String modus = (String) jcb1.getSelectedItem();
|
||||||
|
|
@ -121,8 +121,10 @@ public class ModeSelectionFrame extends JFrame {
|
||||||
boolean zuruecknahme = jb2.isSelected();
|
boolean zuruecknahme = jb2.isSelected();
|
||||||
|
|
||||||
Game game = new Game(modus, rotieren, zuruecknahme, fen);
|
Game game = new Game(modus, rotieren, zuruecknahme, fen);
|
||||||
|
mf.setGame(game);
|
||||||
|
mf.startGame();
|
||||||
|
|
||||||
spiele.add(game);
|
// spiele.add(game);
|
||||||
|
|
||||||
dispose();
|
dispose();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,156 @@
|
||||||
|
package de.mannheim.th.chess.ui;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import javax.swing.BoxLayout;
|
||||||
|
import javax.swing.DefaultListModel;
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JFileChooser;
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JList;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JProgressBar;
|
||||||
|
import javax.swing.JScrollPane;
|
||||||
|
import javax.swing.ListSelectionModel;
|
||||||
|
import javax.swing.SwingWorker;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import com.github.bhlangonijr.chesslib.game.Game;
|
||||||
|
import com.github.bhlangonijr.chesslib.pgn.PgnHolder;
|
||||||
|
import com.github.bhlangonijr.chesslib.pgn.PgnLoadListener;
|
||||||
|
|
||||||
|
public class PGNLoaderFrame extends JFrame {
|
||||||
|
|
||||||
|
private static final Logger logger = LogManager.getLogger(PGNLoaderFrame.class);
|
||||||
|
|
||||||
|
private PgnHolder pgn;
|
||||||
|
private File selectedFile;
|
||||||
|
private List<Game> games;
|
||||||
|
private DefaultListModel<String> gameListModel;
|
||||||
|
private JPanel contentPane;
|
||||||
|
private JList<String> gameList;
|
||||||
|
private JProgressBar progressBar;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opens the PNGLoaderFrame
|
||||||
|
*/
|
||||||
|
public PGNLoaderFrame(MainFrame mf) {
|
||||||
|
|
||||||
|
// ----- Style -----
|
||||||
|
setResizable(true);
|
||||||
|
setAlwaysOnTop(true);
|
||||||
|
setTitle("PGNLoader");
|
||||||
|
setBounds(100, 100, 500, 500);
|
||||||
|
|
||||||
|
// ----- contentPane -----
|
||||||
|
contentPane = new JPanel();
|
||||||
|
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
|
||||||
|
|
||||||
|
setContentPane(contentPane);
|
||||||
|
|
||||||
|
// ----- FileSelector -----
|
||||||
|
JButton fileSelectButton = new JButton("Select File");
|
||||||
|
fileSelectButton.addActionListener(e -> {
|
||||||
|
JFileChooser fileChooser = new JFileChooser();
|
||||||
|
int returnValue = fileChooser.showOpenDialog(null);
|
||||||
|
if (returnValue == JFileChooser.APPROVE_OPTION) {
|
||||||
|
selectedFile = fileChooser.getSelectedFile();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
contentPane.add(fileSelectButton);
|
||||||
|
|
||||||
|
// ----- LoadButton -----
|
||||||
|
JButton loadPgnButton = new JButton("Load file");
|
||||||
|
loadPgnButton.addActionListener(e -> loadFile());
|
||||||
|
contentPane.add(loadPgnButton);
|
||||||
|
|
||||||
|
// ----- SelectionList -----
|
||||||
|
gameListModel = new DefaultListModel<>();
|
||||||
|
gameList = new JList<>(gameListModel);
|
||||||
|
gameList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||||
|
gameList.setVisibleRowCount(5);
|
||||||
|
JScrollPane scrollPane = new JScrollPane(gameList);
|
||||||
|
contentPane.add(scrollPane);
|
||||||
|
|
||||||
|
// ----- ProgressBar -----
|
||||||
|
progressBar = new JProgressBar(0, 100);
|
||||||
|
progressBar.setValue(0);
|
||||||
|
progressBar.setStringPainted(true);
|
||||||
|
contentPane.add(progressBar);
|
||||||
|
|
||||||
|
// ----- StartButton -----
|
||||||
|
JButton startGameButton = new JButton("Starte Spiel");
|
||||||
|
startGameButton.addActionListener(e -> {
|
||||||
|
int index = gameList.getSelectedIndex();
|
||||||
|
de.mannheim.th.chess.domain.Game game = new de.mannheim.th.chess.domain.Game(games.get(index).getHalfMoves());
|
||||||
|
|
||||||
|
mf.setGame(game);
|
||||||
|
mf.startView();
|
||||||
|
});
|
||||||
|
contentPane.add(startGameButton);
|
||||||
|
|
||||||
|
this.setVisible(true);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadFile() {
|
||||||
|
if (this.selectedFile != null) {
|
||||||
|
pgn = new PgnHolder(this.selectedFile.getAbsolutePath());
|
||||||
|
|
||||||
|
LoadPGNWorker loadPGNWorker = new LoadPGNWorker();
|
||||||
|
loadPGNWorker.addPropertyChangeListener(e -> {
|
||||||
|
progressBar.setIndeterminate(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
pgn.getListener().add(loadPGNWorker);
|
||||||
|
loadPGNWorker.execute();
|
||||||
|
|
||||||
|
gameList.revalidate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class LoadPGNWorker extends SwingWorker<Integer, Integer> implements PgnLoadListener {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Integer doInBackground() throws Exception {
|
||||||
|
try {
|
||||||
|
pgn.loadPgn();
|
||||||
|
games = pgn.getGames();
|
||||||
|
int totalGames = games.size();
|
||||||
|
for (int i = 0; i < totalGames; i++) {
|
||||||
|
publish(i);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.info("Could not load pgn file!");
|
||||||
|
}
|
||||||
|
return pgn.getSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void process(List<Integer> chunks) {
|
||||||
|
for (Integer index : chunks) {
|
||||||
|
gameListModel.addElement("Game: " + index);
|
||||||
|
setProgress(Math.min(90, index * 100 / games.size()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void done() {
|
||||||
|
setProgress(100);
|
||||||
|
progressBar.setValue(100);
|
||||||
|
progressBar.setIndeterminate(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void notifyProgress(int games) {
|
||||||
|
setProgress(Math.min(90, games));
|
||||||
|
progressBar.setValue(Math.min(90, games));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -14,9 +14,15 @@ import de.mannheim.th.chess.utl.Clock;
|
||||||
import de.mannheim.th.chess.controller.ButtonAufgebenListener;
|
import de.mannheim.th.chess.controller.ButtonAufgebenListener;
|
||||||
import de.mannheim.th.chess.controller.ButtonFileSaverListener;
|
import de.mannheim.th.chess.controller.ButtonFileSaverListener;
|
||||||
import de.mannheim.th.chess.controller.ButtonMovePieceListener;
|
import de.mannheim.th.chess.controller.ButtonMovePieceListener;
|
||||||
|
import de.mannheim.th.chess.controller.controlPanel.ButtonQuickloadListener;
|
||||||
|
import de.mannheim.th.chess.controller.controlPanel.ButtonQuicksaveListener;
|
||||||
import de.mannheim.th.chess.controller.ButtonSelectPieceListener;
|
import de.mannheim.th.chess.controller.ButtonSelectPieceListener;
|
||||||
import de.mannheim.th.chess.controller.ButtonToNormalListener;
|
import de.mannheim.th.chess.controller.ButtonToNormalListener;
|
||||||
import de.mannheim.th.chess.controller.ButtonUndoMoveListener;
|
import de.mannheim.th.chess.controller.ButtonUndoMoveListener;
|
||||||
|
import de.mannheim.th.chess.controller.controlPanel.ButtonViewBackListener;
|
||||||
|
import de.mannheim.th.chess.controller.controlPanel.ButtonViewFirstListener;
|
||||||
|
import de.mannheim.th.chess.controller.controlPanel.ButtonViewForwardListener;
|
||||||
|
import de.mannheim.th.chess.controller.controlPanel.ButtonViewLastListener;
|
||||||
|
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
|
|
||||||
|
|
@ -36,7 +42,8 @@ import javax.swing.JTextArea;
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.FlowLayout;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -49,7 +56,7 @@ public class SpielFrame extends JFrame {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
private ArrayList<JButton> buttons = new ArrayList<>();
|
private ArrayList<JButton> buttons = new ArrayList<>();
|
||||||
private HashMap<JButton, String> belegungen = new HashMap<>();
|
private HashMap<JButton, String> belegungen = new HashMap<>();
|
||||||
private JPanel panelLinks, panelRechts, contentPane;
|
private JPanel panelLinks, panelRechts, contentPane, controlPanel;
|
||||||
private JButton undo, undo2;
|
private JButton undo, undo2;
|
||||||
private JTextArea ausgabe;
|
private JTextArea ausgabe;
|
||||||
private Game game;
|
private Game game;
|
||||||
|
|
@ -96,6 +103,8 @@ public class SpielFrame extends JFrame {
|
||||||
// Panel für alle Eingaben von Player 2
|
// Panel für alle Eingaben von Player 2
|
||||||
panelRechts.add(getUiPlayerTwo());
|
panelRechts.add(getUiPlayerTwo());
|
||||||
|
|
||||||
|
panelRechts.add(createControlPanel());
|
||||||
|
|
||||||
// Panel für Statistikanzeigen
|
// Panel für Statistikanzeigen
|
||||||
panelRechts.add(getUiStatistik());
|
panelRechts.add(getUiStatistik());
|
||||||
|
|
||||||
|
|
@ -119,14 +128,11 @@ public class SpielFrame extends JFrame {
|
||||||
*/
|
*/
|
||||||
public void erstelleBrett() {
|
public void erstelleBrett() {
|
||||||
|
|
||||||
this.clearButtons();
|
this.setDefaultButtons();
|
||||||
this.setDefaultBackground();
|
|
||||||
this.setButtonsActions();
|
this.setButtonsActions();
|
||||||
|
this.applyBoardButtons();
|
||||||
|
|
||||||
ladeBrett();
|
this.ladeBrett();
|
||||||
|
|
||||||
panelLinks.revalidate();
|
|
||||||
panelLinks.repaint();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -137,7 +143,7 @@ public class SpielFrame extends JFrame {
|
||||||
/**
|
/**
|
||||||
* holt sich FEN-Zeichenkette und extrahiert daraus die Positionen der Figuren
|
* holt sich FEN-Zeichenkette und extrahiert daraus die Positionen der Figuren
|
||||||
*/
|
*/
|
||||||
private void ladeBrett() {
|
public void ladeBrett() {
|
||||||
// System.out.println(game.toFEN());
|
// System.out.println(game.toFEN());
|
||||||
|
|
||||||
char[] fen = game.toFEN().replaceAll("/", "").split(" ")[0].toCharArray();
|
char[] fen = game.toFEN().replaceAll("/", "").split(" ")[0].toCharArray();
|
||||||
|
|
@ -165,6 +171,10 @@ public class SpielFrame extends JFrame {
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
panelLinks.revalidate();
|
||||||
|
panelLinks.repaint();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -208,6 +218,14 @@ public class SpielFrame extends JFrame {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the to default buttons
|
||||||
|
*/
|
||||||
|
public void setDefaultButtons() {
|
||||||
|
this.clearButtons();
|
||||||
|
this.setDefaultBackground();
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Switches the button actions depending on the boardmode
|
* Switches the button actions depending on the boardmode
|
||||||
*/
|
*/
|
||||||
|
|
@ -247,16 +265,14 @@ public class SpielFrame extends JFrame {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case finished:
|
case finished:
|
||||||
clearButtons();
|
// this.enableControlPanelButtons();
|
||||||
|
// this.viewPointer = this.game.getMoveList().size() - 1;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (JButton b : buttons) {
|
|
||||||
panelLinks.add(b);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showDraw() {
|
public void showDraw() {
|
||||||
|
|
@ -313,6 +329,55 @@ public class SpielFrame extends JFrame {
|
||||||
return result[0];
|
return result[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the controlPanel and its Buttons
|
||||||
|
*/
|
||||||
|
private JPanel createControlPanel() {
|
||||||
|
this.controlPanel = new JPanel();
|
||||||
|
this.controlPanel.setBackground(new Color(90, 90, 90));
|
||||||
|
this.controlPanel.setLayout(new FlowLayout());
|
||||||
|
|
||||||
|
this.controlPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, controlPanel.getPreferredSize().height));
|
||||||
|
|
||||||
|
// ----- ViewQuicksaveButton -----
|
||||||
|
JButton quicksave = new JButton("Quicksave");
|
||||||
|
quicksave.setEnabled(true);
|
||||||
|
quicksave.addActionListener(new ButtonQuicksaveListener(this.game));
|
||||||
|
this.controlPanel.add(quicksave);
|
||||||
|
|
||||||
|
// ----- ViewFirstButton -----
|
||||||
|
JButton viewFirstButton = new JButton("<<-");
|
||||||
|
viewFirstButton.setEnabled(false);
|
||||||
|
viewFirstButton.addActionListener(new ButtonViewFirstListener(this.game, this));
|
||||||
|
this.controlPanel.add(viewFirstButton);
|
||||||
|
|
||||||
|
// ----- ViewBackButton -----
|
||||||
|
JButton viewBackButton = new JButton("<-");
|
||||||
|
viewBackButton.setEnabled(false);
|
||||||
|
viewBackButton.addActionListener(new ButtonViewBackListener(this.game, this));
|
||||||
|
this.controlPanel.add(viewBackButton);
|
||||||
|
|
||||||
|
// ----- ViewForwardButton -----
|
||||||
|
JButton viewForwardButton = new JButton("->");
|
||||||
|
viewForwardButton.setEnabled(false);
|
||||||
|
viewForwardButton.addActionListener(new ButtonViewForwardListener(this.game, this));
|
||||||
|
this.controlPanel.add(viewForwardButton);
|
||||||
|
|
||||||
|
// ----- ViewLastButton -----
|
||||||
|
JButton viewLastButton = new JButton("->>");
|
||||||
|
viewLastButton.setEnabled(false);
|
||||||
|
viewLastButton.addActionListener(new ButtonViewLastListener(this.game, this));
|
||||||
|
this.controlPanel.add(viewLastButton);
|
||||||
|
|
||||||
|
// ----- ViewQuickloadButton -----
|
||||||
|
JButton quickload = new JButton("Quickload");
|
||||||
|
quickload.setEnabled(true);
|
||||||
|
quickload.addActionListener(new ButtonQuickloadListener(this.game, this));
|
||||||
|
this.controlPanel.add(quickload);
|
||||||
|
|
||||||
|
return controlPanel;
|
||||||
|
}
|
||||||
|
|
||||||
private JPanel getUiPlayerTwo() {
|
private JPanel getUiPlayerTwo() {
|
||||||
|
|
||||||
JPanel playerTwo = new JPanel();
|
JPanel playerTwo = new JPanel();
|
||||||
|
|
@ -532,4 +597,28 @@ public class SpielFrame extends JFrame {
|
||||||
return clock;
|
return clock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setMode(BoardMode mode) {
|
||||||
|
this.mode = mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inverts the Enabled property of the controlpanelButtons
|
||||||
|
*/
|
||||||
|
public void enableControlPanelButtons() {
|
||||||
|
for (Component c : this.controlPanel.getComponents()) {
|
||||||
|
if (c instanceof JButton) {
|
||||||
|
c.setEnabled(!c.isEnabled());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the buttons to the boardpanel
|
||||||
|
*/
|
||||||
|
public void applyBoardButtons() {
|
||||||
|
for (JButton b : buttons) {
|
||||||
|
panelLinks.add(b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue