alchimya / iOS-Game-15puzzle

A simple SpriteKit implementation of the famous "Fifteen Puzzle" game

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

iOS-Game-15puzzle

A simple SpriteKit implementation of the famous "Fifteen Puzzle" game

ScreenShot
To solve the implementation of this game we have to focus mainly on these issues:

  1. Generate a random series (NSArray) of 16 numbers from 0 to 15, where 0 is the empty tile.

You can find this implementation in the RandomNumberSeries class (an NSArray subclass) where in the initWithSeriesMax method will be added (in our case) 16 random numbers into an array. You can reuse this class for a different pourpose.
  1. Retrieve the “train” of tiles when the user is swiping his finger towards the empty tile.

To solve this issue (see getTrainTilesFromNode into the GameScene class), starting from the touched tile, you have to look toward in the swipe direction if thre is the empty tile.
All the tiles before the empty tile are the "train of tiles".
  1. Move the train of tiles from the first tile to the empty tile when the user swipe his finger.

I have solved this issue by moving the empty tile (last tile into the train of tiles) from its position to the position of the first tile of the train tiles collection.
I used a moveTo SKAction to have a pleasant swiping effect with also a sound effect.

Enjoy! ;-)

About

A simple SpriteKit implementation of the famous "Fifteen Puzzle" game


Languages

Language:Objective-C 100.0%