add rudementary quicksave -load
parent
596a3a4dea
commit
a506f2230d
|
|
@ -0,0 +1,24 @@
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -33,6 +33,8 @@ public class Game {
|
||||||
private String modus;
|
private String modus;
|
||||||
private boolean rotieren, zuruecknahme;
|
private boolean rotieren, zuruecknahme;
|
||||||
|
|
||||||
|
private MoveList savestate;
|
||||||
|
|
||||||
private MoveList movelist;
|
private MoveList movelist;
|
||||||
|
|
||||||
public Game() {
|
public Game() {
|
||||||
|
|
@ -123,6 +125,20 @@ public class Game {
|
||||||
this.movelist.removeLast();
|
this.movelist.removeLast();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void quicksave() {
|
||||||
|
logger.info("Quicksaved");
|
||||||
|
this.savestate = new MoveList(this.movelist);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void quickload() {
|
||||||
|
logger.info("Quickloaded");
|
||||||
|
|
||||||
|
this.board = new Board();
|
||||||
|
for (Move move : savestate) {
|
||||||
|
this.playMove(move);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plays the move on the board and adds it to the movelist
|
* Plays the move on the board and adds it to the movelist
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
@ -402,6 +404,16 @@ public class SpielFrame extends JFrame {
|
||||||
|
|
||||||
statistik.add(scrollPane);
|
statistik.add(scrollPane);
|
||||||
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue