diff --git a/app/src/main/java/de/sopa/model/justplay/JustPlayServiceImpl.java b/app/src/main/java/de/sopa/model/justplay/JustPlayServiceImpl.java index a41d21e9..8d14d7a5 100644 --- a/app/src/main/java/de/sopa/model/justplay/JustPlayServiceImpl.java +++ b/app/src/main/java/de/sopa/model/justplay/JustPlayServiceImpl.java @@ -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() { diff --git a/app/src/main/java/de/sopa/scene/game/GameFieldView.java b/app/src/main/java/de/sopa/scene/game/GameFieldView.java index 3f244874..f3c8047c 100644 --- a/app/src/main/java/de/sopa/scene/game/GameFieldView.java +++ b/app/src/main/java/de/sopa/scene/game/GameFieldView.java @@ -21,8 +21,8 @@ /** - * @author David Schilling - davejs92@gmail.com - * @author Raphael Schilling + * @author David Schilling - davejs92@gmail.com + * @author Raphael Schilling */ public class GameFieldView extends Entity { @@ -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 regionMap, VertexBufferObjectManager vbom, ITextureRegion tilesBorderRegion) { + Map regionMap, VertexBufferObjectManager vbom, ITextureRegion tilesBorderRegion) { super(pX, pY); this.gameService = gameService; @@ -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; @@ -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 textureRegions = Arrays.asList(pTextureRegion, pTextureRegionFilled); @@ -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; @@ -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; @@ -138,13 +141,13 @@ 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) { @@ -152,6 +155,7 @@ protected void onModifierFinished(IEntity pItem) { } gameService.shiftLine(false, row - 1, direction, true); + active = true; this.countModifier = tileSprites[row].length - 2; this.modifierFinished = 0; @@ -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 pTextureRegion, Tile[][] field) { + List pTextureRegion, Tile[][] field) { TileSprite tileSprite; @@ -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(); } diff --git a/app/src/main/java/de/sopa/scene/game/GameScene.java b/app/src/main/java/de/sopa/scene/game/GameScene.java index 7a527052..1a865598 100644 --- a/app/src/main/java/de/sopa/scene/game/GameScene.java +++ b/app/src/main/java/de/sopa/scene/game/GameScene.java @@ -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); } diff --git a/app/src/main/java/de/sopa/scene/game/GameSceneSingleMoveDetector.java b/app/src/main/java/de/sopa/scene/game/GameSceneSingleMoveDetector.java index a61b6b0d..1253e012 100644 --- a/app/src/main/java/de/sopa/scene/game/GameSceneSingleMoveDetector.java +++ b/app/src/main/java/de/sopa/scene/game/GameSceneSingleMoveDetector.java @@ -1,5 +1,6 @@ package de.sopa.scene.game; +import de.sopa.model.game.GameService; import org.andengine.input.touch.detector.HoldDetector; @@ -11,6 +12,7 @@ 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; @@ -18,7 +20,7 @@ public class GameSceneSingleMoveDetector implements HoldDetector.IHoldDetectorLi 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; @@ -26,41 +28,45 @@ public GameSceneSingleMoveDetector(float startX, float startY, float widthPerTil 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; + } } } } @@ -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; } } }