package de.sopa.scene.game;


import android.view.animation.Animation;

import org.andengine.engine.handler.timer.ITimerCallback;
import org.andengine.engine.handler.timer.TimerHandler;
import org.andengine.entity.sprite.ButtonSprite;

import de.sopa.model.game.Level;
import de.sopa.model.game.LevelResult;

/**
 * @author David Schilling - davejs92@gmail.com
 * @author Raphael Schilling
 */
public class LevelModeGameScene extends GameScene {
    private boolean leaveScene;

    public LevelModeGameScene(Object o) {
        super(o);
        leaveScene = false;
    }

    @Override
    protected void addButtons() {
        ButtonSprite restartButton = new ButtonSprite(camera.getWidth() - 300, (camera.getHeight() - 300), resourcesManager.restartRegion, vbom, new ButtonSprite.OnClickListener() {
            @Override
            public void onClick(ButtonSprite pButtonSprite, float pTouchAreaLocalX, float pTouchAreaLocalY) {
                sceneService.loadGameSceneFromGameScene(levelBackup);
            }
        });
        restartButton.setWidth(300);
        restartButton.setHeight(300);
        registerTouchArea(restartButton);
        attachChild(restartButton);
    }

    @Override
    public void onBackKeyPressed() {
        if(!leaveScene) {
            sceneService.loadLevelChoiceSceneFromGameScene();
        }
    }

    public void onSolvedGame() {
        Level level = gameService.getLevel();
        final LevelResult levelResult = levelService.calculateLevelResult(level);
        levelService.persistLevelResult(levelResult);
        int nextLevelId = level.getId() + 1;
        levelService.unlockLevel(nextLevelId);
        this.leaveScene = true;
        engine.registerUpdateHandler(new TimerHandler(1.5f,new ITimerCallback() {
            @Override
            public void onTimePassed(TimerHandler pTimerHandler) {
                engine.unregisterUpdateHandler(pTimerHandler);
                sceneService.loadScoreScreen(levelResult);
            }
        }));

    }
}

@@ -470,16 +470,56 @@
 veScene;
+%0A    private ButtonSprite restartButton;
 %0A%0A    pu
@@ -663,29 +663,16 @@
         
-ButtonSprite 
 restartB
@@ -1397,24 +1397,65 @@
 vedGame() %7B%0A
+        restartButton.setVisible(false);%0A
         Leve

remove restart button on solve game