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