dcsimg
A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: 3x3 slide puzzle

  1. #1
    Junior Member
    Join Date
    Aug 2010
    Posts
    1

    3x3 slide puzzle

    I am currently attempting to build a 3x3 slide puzzle (the ones where one space is empty and you slide the other pieces into the empty slot until the picture is back in order) and am wanting to make it so that when a piece is clicked it will switch places with the empty piece if it is touching it. Does anyone know of either a good tutorial site where I could find out how to do this or have any suggestions as to what the switching code should be? I am working in Flash CS5 using Actionscript 3.0. Thank you in advance for any ideas.

  2. #2
    An FKer
    Join Date
    Sep 2005
    Location
    Ontario
    Posts
    1,167
    The best way to go about that would be to learn about 2D arrays, since they take on the 'shape' of a grid. You would then just number each piece of the puzzle from 1-9, and place that number into the array to represent each piece.

    Assuming that 1 is the blank tile, you could always check through the surrounding 'four' parts of the array to see if the selected tile is touching the part of the array with the number 1. If so, move and update the array:

    [[5,2,9],
    [3,1,4],
    [8,6,7]];

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center