Following features are supported :-
4*4 slider puzzle, grid scale is stored in shared preferences, can be customized
Clicking on a tile is sliding it to an open space, including multiple tiles legal move
Dragging smoothly move tiles, including multiple tiles legal move.
On releasing the drag(for a tile and multiple tiles), if move is over halfway to complete, the move is completed and if less than halfway, tiles are reverted to original position.
Puzzle is locked for portrait screen.
Target SDK is 23 and build tools versions is “23.0.2” and minimum API support is 17(Android 4.2)
- Once the puzzle is solved “success” toast message is displayed
Screen -1: Image is sliced into small bitmaps and randomly displayed on screen.
Screen-2 : Once the puzzle is solved, sucess toast is shown
===================
===================
View:--
- PuzzleBoardLayout extends RelativeLayout and is inflated dynamically.
- Each tile is a imageview, which stores coordinates, the image slice, and image slice handle. This handle is used to calculate the completion of puzzle.
- PuzzleBoard (RectF)is created in which the tiles are placed.
- Each imageView tile registers ontouchlistener.
- This registered event is captured in the PuzzleBoardLayout to check for touch or drag action events.
Processor:--
-
ImageProcessor:- a) This scales the bitmap to PuzzleBoard dimensions. b) Once the image is scaled, it is sliced into n*n pieces. c) Each image is placed on the tile randomly.
-
PuzzleProcessor a) This class handles all the processing logic for movement, dragging and then finally swaping the tiles using the TileDataTransferObject(s)
Model:
- TileDataTransferObject:-
a) This object stores all the transfer data information of a tile, the displacement information between various touch points, and the tile rectangle drawing information. b) Once the tiles movement are validated, the required data to be swiped between the two tiles is stored in this.
- PuzzleTile:
a) This store the Tiles coordinate information which is used to draw tile rectangle in layout. b) It stores the correct image slice handle, which is used to calculate the success of puzzle completion.
The puzzle grid size is stored in shared preferences, and can be customized by preference screen easily.