Skip to content

Commit

Permalink
fix bug when not continuing to score screen
Browse files Browse the repository at this point in the history
References #46
  • Loading branch information
djschilling committed Aug 24, 2015
1 parent 09a8e2a commit 16c0601
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ public class JustPlayServiceImpl implements JustPlayService {
private final LevelCreator levelCreator;
private int leftTime;
private int lastScore;
private int[] difficultyGameSize = { 4, 5, 5, 6, 6, 6, 6 };
private int[] difficultyMoves = { 1, 2, 3, 2, 3, 4, 4 };
private int[] difficultyTime = { 3, 4, 5, 6, 8, 14, 12 };
private int[] difficultyScore = { 50, 70, 100, 100, 150, 250, 350 };
private int[] difficultyGameSize = { 4, 5, 5, 6, 6, 6, 6 };
private int[] difficultyMoves = { 1, 2, 3, 2, 3, 4, 4 };
private int[] difficultyTime = { 3, 4, 5, 6, 8, 14, 12 };
private int[] difficultyScore = { 50, 70, 100, 100, 150, 250, 350 };

public JustPlayServiceImpl() {

Expand Down
67 changes: 28 additions & 39 deletions app/src/main/java/de/sopa/scene/game/GameFieldView.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@


/**
* @author David Schilling - [email protected]
* @author Raphael Schilling
* @author David Schilling - [email protected]
* @author Raphael Schilling
*/
public class GameFieldView extends Entity {

Expand All @@ -32,15 +32,13 @@ public class GameFieldView extends Entity {
private final VertexBufferObjectManager vbom;
private final ITextureRegion tilesBorderRegion;
private TileSprite[][] tileSprites;
private TileSprite start;
private TileSprite finish;
private boolean active = true;
private boolean active = false;

private int countModifier;
private int modifierFinished;

public GameFieldView(float pX, float pY, float spacePerTile, GameService gameService,
Map<Character, TextureRegion> regionMap, VertexBufferObjectManager vbom, ITextureRegion tilesBorderRegion) {
Map<Character, TextureRegion> regionMap, VertexBufferObjectManager vbom, ITextureRegion tilesBorderRegion) {

super(pX, pY);
this.gameService = gameService;
Expand All @@ -60,7 +58,11 @@ public void addTiles(boolean finished) {
tileIndex = 0;
}


detachChildren();
if (active){
oneModifierFinished(true);
}

Tile[][] field = gameService.getLevel().getField();
int width = field.length;
Expand All @@ -76,7 +78,7 @@ public void addTiles(boolean finished) {
if (field[x][y].getShortcut() != 'n') {
TextureRegion pTextureRegion = tileRegionMap.get(field[x][y].getShortcut());
TextureRegion pTextureRegionFilled = tileRegionMap.get(Character.toUpperCase(
field[x][y].getShortcut()));
field[x][y].getShortcut()));
List<ITextureRegion> textureRegions = Arrays.<ITextureRegion>asList(pTextureRegion,
pTextureRegionFilled);

Expand All @@ -91,12 +93,12 @@ public void addTiles(boolean finished) {
break;

case FINISH:
finish = createFinishAnsStart(x, y, tilePositionX, tilePositionY, textureRegions, field);
TileSprite finish = createFinishAnsStart(x, y, tilePositionX, tilePositionY, textureRegions, field);
finish.setITextureRegionIndex(tileIndex);
break;

case START:
start = createFinishAnsStart(x, y, tilePositionX, tilePositionY, textureRegions, field);
TileSprite start = createFinishAnsStart(x, y, tilePositionX, tilePositionY, textureRegions, field);
start.setITextureRegionIndex(tileIndex);
break;

Expand Down Expand Up @@ -130,6 +132,7 @@ public void oneStep(final boolean horizontal, int row, final int direction) {
}

gameService.shiftLine(true, row - 1, direction, true);
active = true;
this.countModifier = tileSprites.length - 2;
this.modifierFinished = 0;

Expand All @@ -138,20 +141,21 @@ public void oneStep(final boolean horizontal, int row, final int direction) {
tileSprite.registerEntityModifier(new MoveXModifier(0.3f, tileSprite.getX(),
tileSprite.getX() + tileSprite.getWidth() * direction, EaseQuadInOut.getInstance()) {

@Override
protected void onModifierFinished(IEntity pItem) {
@Override
protected void onModifierFinished(IEntity pItem) {

oneModifierFinished();
super.onModifierFinished(pItem);
}
});
oneModifierFinished(false);
super.onModifierFinished(pItem);
}
});
}
} else {
if (row > tileSprites[0].length - 2) {
return;
}

gameService.shiftLine(false, row - 1, direction, true);
active = true;
this.countModifier = tileSprites[row].length - 2;
this.modifierFinished = 0;

Expand All @@ -160,20 +164,20 @@ protected void onModifierFinished(IEntity pItem) {
tileSprite.registerEntityModifier(new MoveYModifier(0.3f, tileSprite.getY(),
tileSprite.getY() + tileSprite.getWidth() * direction, EaseQuadInOut.getInstance()) {

@Override
protected void onModifierFinished(IEntity pItem) {
@Override
protected void onModifierFinished(IEntity pItem) {

oneModifierFinished();
super.onModifierFinished(pItem);
}
});
oneModifierFinished(false);
super.onModifierFinished(pItem);
}
});
}
}
}


private TileSprite createFinishAnsStart(int x, int y, float tilePositionX, float tilePositionY,
List<ITextureRegion> pTextureRegion, Tile[][] field) {
List<ITextureRegion> pTextureRegion, Tile[][] field) {

TileSprite tileSprite;

Expand Down Expand Up @@ -213,26 +217,11 @@ public void dispose() {
}


public void setTubesState(int state) {

for (TileSprite[] tileSprite : tileSprites) {
for (TileSprite currentSprite : tileSprite) {
if (currentSprite != null) {
currentSprite.setITextureRegionIndex(state);
}
}
}

start.setITextureRegionIndex(state);
finish.setITextureRegionIndex(state);
}


private void oneModifierFinished() {
private void oneModifierFinished(boolean now) {

modifierFinished++;

if (modifierFinished == countModifier) {
if (modifierFinished == countModifier | now) {
active = false;
gameService.notifyAllObserver();
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/de/sopa/scene/game/GameScene.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ private void addScoreText() {
private void registerTouchHandler() {

GameSceneSingleMoveDetector gameSceneSingleMoveDetector = new GameSceneSingleMoveDetector(0,
getTileSceneStartY() + spacePerTile, spacePerTile, gameFieldView);
getTileSceneStartY() + spacePerTile, spacePerTile, gameFieldView, gameService);
continuousHoldDetector = new ContinuousHoldDetector(0, 100, 0.01f, gameSceneSingleMoveDetector);
setOnSceneTouchListener(continuousHoldDetector);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.sopa.scene.game;

import de.sopa.model.game.GameService;
import org.andengine.input.touch.detector.HoldDetector;


Expand All @@ -11,56 +12,61 @@ public class GameSceneSingleMoveDetector implements HoldDetector.IHoldDetectorLi

private final float SWIPE_SENSITIVITY;
private final float fieldStartX;
private final GameService gameService;
private float firstX;
private float firstY;
private float widthPerTile;
private GameFieldView gameFieldView;
private float fieldStartY;
private boolean isMoved;

public GameSceneSingleMoveDetector(float startX, float startY, float widthPerTile, GameFieldView gameFieldView) {
public GameSceneSingleMoveDetector(float startX, float startY, float widthPerTile, GameFieldView gameFieldView, GameService gameService) {

this.fieldStartX = startX;
this.fieldStartY = startY;
this.widthPerTile = widthPerTile;
this.gameFieldView = gameFieldView;
isMoved = false;
SWIPE_SENSITIVITY = widthPerTile * 0.1f;
this.gameService = gameService;
}

@Override
public void onHoldStarted(HoldDetector pHoldDetector, int pPointerID, float pHoldX, float pHoldY) {

firstX = pHoldX;
firstY = pHoldY;
isMoved = false;
if(!gameService.solvedPuzzle()){
firstX = pHoldX;
firstY = pHoldY;
isMoved = false;
}
}


@Override
public void onHold(HoldDetector pHoldDetector, long pHoldTimeMilliseconds, int pPointerID, float pHoldX,
float pHoldY) {
if(!gameService.solvedPuzzle()) {
int row;

if (!isMoved) {
if (pHoldX - firstX > widthPerTile) {
row = (int) ((firstY - fieldStartY) / widthPerTile);
gameFieldView.oneStep(true, row, 1);

int row;

if (!isMoved) {
if (pHoldX - firstX > widthPerTile) {
row = (int) ((firstY - fieldStartY) / widthPerTile);
gameFieldView.oneStep(true, row, 1);

isMoved = true;
} else if (firstX - pHoldX > widthPerTile) {
row = (int) ((firstY - fieldStartY) / widthPerTile);
gameFieldView.oneStep(true, row, -1);
isMoved = true;
} else if (pHoldY - firstY > widthPerTile) {
row = (int) ((firstX - fieldStartX) / widthPerTile);
gameFieldView.oneStep(false, row, 1);
isMoved = true;
} else if (firstY - pHoldY > widthPerTile) {
row = (int) ((firstX - fieldStartX) / widthPerTile);
gameFieldView.oneStep(false, row, -1);
isMoved = true;
isMoved = true;
} else if (firstX - pHoldX > widthPerTile) {
row = (int) ((firstY - fieldStartY) / widthPerTile);
gameFieldView.oneStep(true, row, -1);
isMoved = true;
} else if (pHoldY - firstY > widthPerTile) {
row = (int) ((firstX - fieldStartX) / widthPerTile);
gameFieldView.oneStep(false, row, 1);
isMoved = true;
} else if (firstY - pHoldY > widthPerTile) {
row = (int) ((firstX - fieldStartX) / widthPerTile);
gameFieldView.oneStep(false, row, -1);
isMoved = true;
}
}
}
}
Expand All @@ -70,27 +76,29 @@ public void onHold(HoldDetector pHoldDetector, long pHoldTimeMilliseconds, int p
public void onHoldFinished(HoldDetector pHoldDetector, long pHoldTimeMilliseconds, int pPointerID, float pHoldX,
float pHoldY) {

int row;

if (!isMoved) {
if (Math.abs(pHoldX - firstX) > Math.abs(pHoldY - firstY)) {
if (pHoldX - firstX > SWIPE_SENSITIVITY) {
row = (int) ((firstY - fieldStartY) / widthPerTile);
gameFieldView.oneStep(true, row, 1);
if(!gameService.solvedPuzzle()) {
int row;

if (!isMoved) {
if (Math.abs(pHoldX - firstX) > Math.abs(pHoldY - firstY)) {
if (pHoldX - firstX > SWIPE_SENSITIVITY) {
row = (int) ((firstY - fieldStartY) / widthPerTile);
gameFieldView.oneStep(true, row, 1);
isMoved = true;
} else if (firstX - pHoldX > SWIPE_SENSITIVITY) {
row = (int) ((firstY - fieldStartY) / widthPerTile);
gameFieldView.oneStep(true, row, -1);
isMoved = true;
}
} else if (pHoldY - firstY > SWIPE_SENSITIVITY) {
row = (int) ((firstX - fieldStartX) / widthPerTile);
gameFieldView.oneStep(false, row, 1);
isMoved = true;
} else if (firstX - pHoldX > SWIPE_SENSITIVITY) {
row = (int) ((firstY - fieldStartY) / widthPerTile);
gameFieldView.oneStep(true, row, -1);
} else if (firstY - pHoldY > SWIPE_SENSITIVITY) {
row = (int) ((firstX - fieldStartX) / widthPerTile);
gameFieldView.oneStep(false, row, -1);
isMoved = true;
}
} else if (pHoldY - firstY > SWIPE_SENSITIVITY) {
row = (int) ((firstX - fieldStartX) / widthPerTile);
gameFieldView.oneStep(false, row, 1);
isMoved = true;
} else if (firstY - pHoldY > SWIPE_SENSITIVITY) {
row = (int) ((firstX - fieldStartX) / widthPerTile);
gameFieldView.oneStep(false, row, -1);
isMoved = true;
}
}
}
Expand Down

0 comments on commit 16c0601

Please sign in to comment.