-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Visile lesstime warnig in the JustPlay Modus
- Loading branch information
Raphael
committed
Sep 8, 2015
1 parent
3b53c8c
commit 9460893
Showing
2 changed files
with
54 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,25 +13,32 @@ | |
import org.andengine.engine.handler.timer.ITimerCallback; | ||
import org.andengine.engine.handler.timer.TimerHandler; | ||
|
||
import org.andengine.entity.IEntity; | ||
import org.andengine.entity.modifier.AlphaModifier; | ||
import org.andengine.entity.modifier.IEntityModifier; | ||
import org.andengine.entity.primitive.Rectangle; | ||
import org.andengine.entity.sprite.ButtonSprite; | ||
import org.andengine.entity.text.Text; | ||
import org.andengine.util.modifier.IModifier; | ||
|
||
|
||
/** | ||
* David Schilling - [email protected]. | ||
*/ | ||
public class JustPlayGameScene extends GameScene implements JustPlaySceneObserver { | ||
|
||
private final JustPlayLevel justPlayLevel; | ||
private TimeBasedGameService timeBasedGameService; | ||
private Text leftTime; | ||
private boolean leaveScene; | ||
private ButtonSprite restartButton; | ||
private Rectangle gameViewBackground; | ||
|
||
public JustPlayGameScene(JustPlayLevel justPlayLevel) { | ||
|
||
super(justPlayLevel.getLevel()); | ||
this.justPlayLevel = justPlayLevel; | ||
gameViewBackground = new Rectangle(0f, getTileSceneStartY() + spacePerTile, camera.getWidth(), camera.getWidth(), vbom); | ||
gameViewBackground.setColor(1f,1f,1f,0f); | ||
attachChild(gameViewBackground); | ||
leaveScene = false; | ||
timeBasedGameService = new TimeBasedGameServiceImpl(justPlayLevel.getLeftTime()); | ||
timeBasedGameService.start(); | ||
|
@@ -43,7 +50,6 @@ public JustPlayGameScene(JustPlayLevel justPlayLevel) { | |
public JustPlayGameScene(TimeBasedGameService timeBasedGameService, JustPlayLevel justPlayLevel) { | ||
|
||
super(justPlayLevel.getLevel()); | ||
this.justPlayLevel = justPlayLevel; | ||
leaveScene = false; | ||
this.timeBasedGameService = timeBasedGameService; | ||
|
||
|
@@ -137,9 +143,9 @@ public void onTimePassed(TimerHandler pTimerHandler) { | |
|
||
engine.unregisterUpdateHandler(pTimerHandler); | ||
storyService.loadJustPlayScoreSceneFromJustPlayScene( | ||
new JustPlayLevelResult(timeBasedGameService.getRemainingTime(), | ||
gameService.getLevel().getMovesCount(), | ||
gameService.getLevel().getMinimumMovesToSolve())); | ||
new JustPlayLevelResult(timeBasedGameService.getRemainingTime(), | ||
gameService.getLevel().getMovesCount(), | ||
gameService.getLevel().getMinimumMovesToSolve())); | ||
} | ||
})); | ||
} | ||
|
@@ -152,18 +158,9 @@ public void onLostGame() { | |
if (!leaveScene) { | ||
restartButton.setEnabled(false); | ||
leaveScene = true; | ||
engine.registerUpdateHandler(new TimerHandler(1f, new ITimerCallback() { | ||
|
||
@Override | ||
public void onTimePassed(TimerHandler pTimerHandler) { | ||
|
||
engine.unregisterUpdateHandler(pTimerHandler); | ||
storyService.loadJustPlayLostSceneFromJustPlayScene( | ||
new JustPlayLevelResult(-1, gameService.getLevel().getMovesCount(), | ||
gameService.getLevel().getMinimumMovesToSolve())); | ||
} | ||
})); | ||
} | ||
storyService.loadJustPlayLostSceneFromJustPlayScene(new JustPlayLevelResult(-1, | ||
gameService.getLevel().getMovesCount(), gameService.getLevel().getMinimumMovesToSolve())); | ||
} | ||
} | ||
|
||
|
||
|
@@ -180,15 +177,36 @@ public void updateJustPlayScene() { | |
|
||
engine.registerUpdateHandler(new TimerHandler(0.1f, new ITimerCallback() { | ||
|
||
@Override | ||
public void onTimePassed(TimerHandler pTimerHandler) { | ||
@Override | ||
public void onTimePassed(TimerHandler pTimerHandler) { | ||
|
||
leftTime.setText(String.valueOf(timeBasedGameService.getRemainingTime())); | ||
} | ||
})); | ||
leftTime.setText(String.valueOf(timeBasedGameService.getRemainingTime())); | ||
if (timeBasedGameService.getRemainingTime() <= 5) { | ||
backgroundFlash(); | ||
} | ||
} | ||
})); | ||
|
||
if (timeBasedGameService.getRemainingTime() == 0 && !gameService.solvedPuzzle()) { | ||
onLostGame(); | ||
} | ||
} | ||
|
||
private void backgroundFlash() { | ||
final AlphaModifier alphaModifier1 = new AlphaModifier(0.1f, 0f, 1f); | ||
final AlphaModifier alphaModifier2 = new AlphaModifier(0.1f, 1f, 0f); | ||
alphaModifier1.addModifierListener(new IEntityModifier.IEntityModifierListener() { | ||
@Override | ||
public void onModifierStarted(IModifier<IEntity> pModifier, IEntity pItem) { | ||
|
||
} | ||
|
||
@Override | ||
public void onModifierFinished(IModifier<IEntity> pModifier, IEntity pItem) { | ||
alphaModifier2.reset(); | ||
gameViewBackground.registerEntityModifier(alphaModifier2); | ||
} | ||
}); | ||
gameViewBackground.registerEntityModifier(alphaModifier1); | ||
} | ||
} |