Skip to content

Commit

Permalink
Add Visile lesstime warnig in the JustPlay Modus
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphael committed Sep 8, 2015
1 parent 3b53c8c commit 9460893
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 27 deletions.
17 changes: 13 additions & 4 deletions app/src/main/java/de/sopa/scene/game/GameScene.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,18 @@
import org.andengine.engine.handler.timer.TimerHandler;

import org.andengine.entity.scene.background.Background;
import org.andengine.entity.scene.background.IBackground;
import org.andengine.entity.scene.background.modifier.ColorBackgroundModifier;
import org.andengine.entity.scene.background.modifier.IBackgroundModifier;
import org.andengine.entity.text.Text;

import org.andengine.input.touch.detector.ContinuousHoldDetector;

import org.andengine.util.color.Color;
import org.andengine.util.modifier.IModifier;
import org.andengine.util.modifier.ease.EaseExponentialIn;
import org.andengine.util.modifier.ease.EaseQuadIn;
import org.andengine.util.modifier.ease.EaseQuadInOut;


/**
Expand All @@ -26,11 +33,12 @@ public abstract class GameScene extends BaseScene implements GameSceneObserver {

protected GameService gameService;
private ContinuousHoldDetector continuousHoldDetector;
private float spacePerTile;
protected float spacePerTile;
private Text scoreText;
private GameFieldView gameFieldView;
protected GameFieldView gameFieldView;
protected final Level level;
protected Level levelBackup;
protected Background background;

public GameScene(Level level) {

Expand Down Expand Up @@ -104,7 +112,7 @@ private void calculateSpacePerTile(int width) {
}


private float getTileSceneStartY() {
protected float getTileSceneStartY() {

return (camera.getHeight() - (spacePerTile * gameService.getLevel().getField().length)) / 2;
}
Expand Down Expand Up @@ -148,7 +156,8 @@ private void registerTouchHandler() {

private void addBackground() {

setBackground(new Background(Color.BLACK));
background = new Background(Color.BLACK);
setBackground(background);
}


Expand Down
64 changes: 41 additions & 23 deletions app/src/main/java/de/sopa/scene/justplay/JustPlayGameScene.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;

Expand Down Expand Up @@ -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()));
}
}));
}
Expand All @@ -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()));
}
}


Expand All @@ -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);
}
}

0 comments on commit 9460893

Please sign in to comment.