niccs / SliderPuzzle

To build a native android of a 4x4 slider puzzle. Clicking or tapping on a tile should slide it to an open space

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

4*4 Slider-Puzzle:

Features supported:

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 Flow

Screen -1: Image is sliced into small bitmaps and randomly displayed on screen.

Screen-1

Screen-2 : Once the puzzle is solved, sucess toast is shown

Screen-2

Process Flow Diagram:--

===================

Process flow diagram

High Level Process Flow:--

===================

View:--

  1. PuzzleBoardLayout extends RelativeLayout and is inflated dynamically.
  2. 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.
  3. PuzzleBoard (RectF)is created in which the tiles are placed.
  4. Each imageView tile registers ontouchlistener.
  5. This registered event is captured in the PuzzleBoardLayout to check for touch or drag action events.

Processor:--

  1. 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.

  2. PuzzleProcessor a) This class handles all the processing logic for movement, dragging and then finally swaping the tiles using the TileDataTransferObject(s)

Model:

  1. 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.

  1. 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.

About

To build a native android of a 4x4 slider puzzle. Clicking or tapping on a tile should slide it to an open space


Languages

Language:Java 100.0%