merge quicksave
commit
f3cd880c9e
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
@ -36,17 +36,22 @@ public class Game {
|
|||
private MoveList movelist;
|
||||
private int viewPointer;
|
||||
|
||||
public Game() {
|
||||
|
||||
this.board = new Board();
|
||||
this.movelist = new MoveList();
|
||||
clock = new Clock("blitz");
|
||||
clock.start();
|
||||
}
|
||||
private MoveList savestate;
|
||||
private String startPosFen;
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
this.modus = modus;
|
||||
this.rotieren = rotieren;
|
||||
|
|
@ -59,6 +64,7 @@ public class Game {
|
|||
|
||||
this.board.loadFromFen(fen);
|
||||
|
||||
this.startPosFen = this.board.getFen();
|
||||
this.movelist = new MoveList();
|
||||
|
||||
clock = new Clock(modus);
|
||||
|
|
@ -75,6 +81,8 @@ public class Game {
|
|||
public Game(MoveList movelist) {
|
||||
this.board = new Board();
|
||||
|
||||
this.startPosFen = this.board.getFen();
|
||||
|
||||
this.movelist = movelist;
|
||||
|
||||
for (Move move : movelist) {
|
||||
|
|
@ -95,6 +103,7 @@ public class Game {
|
|||
this.board.loadFromFen(fen);
|
||||
|
||||
this.movelist = new MoveList();
|
||||
this.startPosFen = this.board.getFen();
|
||||
// this.sp = new SpielFrame();
|
||||
|
||||
// this.clockPlayer1 = new Clock();
|
||||
|
|
@ -124,6 +133,36 @@ public class Game {
|
|||
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
|
||||
*
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ import de.mannheim.th.chess.utl.Clock;
|
|||
import de.mannheim.th.chess.controller.ButtonAufgebenListener;
|
||||
import de.mannheim.th.chess.controller.ButtonFileSaverListener;
|
||||
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.ButtonToNormalListener;
|
||||
import de.mannheim.th.chess.controller.ButtonUndoMoveListener;
|
||||
|
|
@ -433,6 +435,17 @@ public class SpielFrame extends JFrame {
|
|||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue