Skip to content

Commit 9b51c43

Browse files
committed
Only move tiles if all tiles have a move.
1 parent f15edea commit 9b51c43

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/com/tackmobile/GameboardView.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ protected boolean lastDragMovedAtLeastHalfWay() {
130130
}
131131

132132
protected void moveDraggedTilesByMotionEventDelta(MotionEvent event) {
133-
boolean impossibleMove;
133+
boolean impossibleMove = true;
134134
float dxTile, dyTile;
135135
float dxEvent = event.getRawX() - lastDragPoint.x;
136136
float dyEvent = event.getRawY() - lastDragPoint.y;
@@ -142,13 +142,19 @@ protected void moveDraggedTilesByMotionEventDelta(MotionEvent event) {
142142

143143
RectF candidateRect = new RectF(dxTile, dyTile, dxTile + tile.getWidth(), dyTile + tile.getHeight());
144144
boolean candidateRectInGameboard = (gameboardRect.contains(candidateRect));
145-
//Ln.d("In gameboard? %b", candidateRectInGameboard);
146-
impossibleMove = (candidateRectForTileCollidesWithAnyOtherTile(tile, candidateRect) || !candidateRectInGameboard);
147-
if (!impossibleMove) {
148-
if (tile.coordinate.row == emptyTile.coordinate.row) {
149-
tile.setX(dxTile);
150-
} else if (tile.coordinate.column == emptyTile.coordinate.column) {
151-
tile.setY(dyTile);
145+
impossibleMove = impossibleMove && (!candidateRectInGameboard || candidateRectForTileCollidesWithAnyOtherTile(tile, candidateRect));
146+
}
147+
if (!impossibleMove) {
148+
for (GameTileMotionDescriptor gameTileMotionDescriptor : currentMotionDescriptors) {
149+
tile = gameTileMotionDescriptor.tile;
150+
dxTile = tile.getX() + dxEvent;
151+
dyTile = tile.getY() + dyEvent;
152+
if (!impossibleMove) {
153+
if (tile.coordinate.row == emptyTile.coordinate.row) {
154+
tile.setX(dxTile);
155+
} else if (tile.coordinate.column == emptyTile.coordinate.column) {
156+
tile.setY(dyTile);
157+
}
152158
}
153159
}
154160
}

0 commit comments

Comments
 (0)