1 package de.jos.game.objects.buttons;
2
3 import de.jos.game.logic.AbstractGameLogic;
4 import de.jos.game.logic.BoardUtils;
5 import de.jos.game.logic.PuzzleGameBoard;
6 import de.jos.game.objects.screen.AbstractGameObject;
7 import de.jos.game.objects.screen.TheGame;
8
9 public class UndoButton extends GameButton {
10
11 /***
12 * Undo Button an angegebener Position erzeugen
13 *
14 * @param gameObject
15 * @param x
16 * @param y
17 */
18 public UndoButton(AbstractGameObject gameObject, int x, int y) {
19 super(gameObject.getString("menu.undo"), x, y, 0, 0, gameObject);
20
21 setButtonClickCallback(new UndoButtonClickCallback(gameObject));
22 }
23
24 @Override
25 public Action getAction() {
26 return Action.UNDO;
27 }
28
29 /***
30 * Callback fuer einen Button click.
31 *
32 * @author root
33 *
34 */
35 private static final class UndoButtonClickCallback implements ButtonClickCallback {
36
37 AbstractGameObject gameObject = null;
38
39 public UndoButtonClickCallback(AbstractGameObject gameObject) {
40 this.gameObject = gameObject;
41 }
42
43 /***
44 * {@inheritDoc}
45 */
46 public void performClickAction() {
47 TheGame theGame = (TheGame) gameObject;
48
49
50 if (BoardUtils.getAllBoardBullets(theGame.getBoard()).isEmpty() == true) {
51 return;
52 }
53
54 AbstractGameLogic gameLogic = theGame.getGameLogic();
55
56
57 int moves = gameLogic.getBoard().getActionContainer().getActionMoveStatistics().getMoves();
58 if (moves > 0) {
59 gameLogic.getBoard().getActionContainer().getActionMoveStatistics().updateMoves(-1);
60 ((PuzzleGameBoard) gameLogic.getBoard()).undoBoardHistory();
61 }
62 }
63
64 }
65
66 }