merge quicksave

pgnReader
dstuck 2025-06-24 17:52:32 +02:00
commit f3cd880c9e
4 changed files with 103 additions and 7 deletions

View File

@ -0,0 +1,25 @@
package de.mannheim.th.chess.controller;
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();
}
}

View File

@ -0,0 +1,19 @@
package de.mannheim.th.chess.controller;
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();
}
}

View File

@ -36,17 +36,22 @@ public class Game {
private MoveList movelist; private MoveList movelist;
private int viewPointer; 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;
@ -59,6 +64,7 @@ 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);
@ -75,6 +81,8 @@ 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) {
@ -95,6 +103,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();
@ -124,6 +133,36 @@ 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
* *

View File

@ -14,6 +14,8 @@ 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.ButtonQuickloadListener;
import de.mannheim.th.chess.controller.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;
@ -433,6 +435,17 @@ public class SpielFrame extends JFrame {
statistik.add(scrollPane); statistik.add(scrollPane);
// TODO: Buttons should be somewhere else
JButton quicksave = new JButton();
quicksave.addActionListener(new ButtonQuicksaveListener(this.game));
quicksave.setText("Quicksave");
statistik.add(quicksave);
JButton quickload = new JButton();
quickload.addActionListener(new ButtonQuickloadListener(this.game, this));
quickload.setText("Quickload");
statistik.add(quickload);
return statistik; return statistik;
} }