Here is the capx of a Fifteen game I made (the tiles are a bit small, but they are going to be replaced by a larger image at the end).Fifteen Game capx
And here's the screenshot :
(By the way, I'm using the Random Array plugin)
As you can see, the logic I tried to make to switch between tiles is a bit strange, since at the time I didn't want to use a second array to store the game. In fact, I store the properties of the tile I clicked on, I move the mouse with the left button pressed, and I store the properties of the tile I lifted my finger on. If the two are a tile next to the empty spot, the move is "valid". With that, I have the problem that I can jump across the board, if the destination spot is the empy spot...
Right now, I have two more problems : the first one (which is minor and doesn't bother me if I can't do it another way) is that I want to slide the tile with the mouse, without going outside the grid, and without allowing collision without another Sprite (just letting the player go to the empty spot with his selected tile). For the moment, there is no "sliding" movement. I validate the tile switch after the gesture, and there is nothing "dynamic". Anyway, it's just a cosmetic problem so it's not the biggest one.
The other problem is that I want a "victory" condition. For that, I need to know if the tiles are in the right order. Since I don't use an array (and using an array seems difficult for me in that context of "sliding" tiles), I need to find a quick trick to do that.
One of my idea was to use an invisible "growing bar" on the left of the game, which count the tile it intersect at each tick, and if the order of those tiles is the right one (i.e. "1", "2", "3", and "4"), then that row is good ! Repeat that for the 4 rows, and we have a victory condition...
In the end, I think that all my code is overly complicated and that the victory condition can be made simpler. Does anybody have an idea ?