> Hi Danny, > > Thanks for the reply.. I'm not quite sure to what you mean, but doesn't it > sound similar to my current approach? Rather than using arrays, you > suggested objects. Please correct me if I'm wrong.
Hi, Guntur, I've been on holiday, but in case it's helpful, a little clarification: >From my original post: >Without going into your post in detail, I think this is the source of your problem. For each group, you're better off making a single object which contains all the elements in it, then making A.group a reference to that object. Start with N such groups, one for each piece. Then, when you connect two pieces, you merge their groups into a single object. Now, each time the user drags a piece, update the whole group (including the piece clicked on) with a single command. The point of this is to keep the groups and the pieces as separate things. Here's a pseudocode explanation: start with an array of n Piece objects and an array of n Group objects. - Each piece knows its neighbours and belongs to exactly one group, to which it has a reference. - Each group knows which pieces it contains. - Initially, each group contains one piece when a piece is clicked, tell its group to start dragging (and bring all its pieces to the top) when dragging a group, move all its pieces simultaneously (so the 'drag' method is part of the Group object, not the Piece object) when a group is released, check if any of its pieces can be linked to one of its neighbours that is not in the group. If so: - set group1 to the group of the first piece - set group2 to the group of the second piece - add all the elements of group2 to group1 - set the group of each element of group2 to group1 - delete group2 - if at this stage there is only one group left, the puzzle is complete NB: with a little ingenuity, checking if two groups can be linked should be possible to do in a single test, rather than looping through all pieces in them. I'd do it by noting the offset of each group from its correct position, then checking how similar these values are in the two groups. Is that clearer? Danny _______________________________________________ [email protected] To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com

