Code Monkey home page Code Monkey logo

ios-game-15puzzle's Introduction

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! ;-)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.