2D Array images swapping
-
08-10-2019 - |
Question
i have a problem of how to swap images isnide my 3 * 3 array, for example:
mImage image1 image2
image3 image4 image5
image6 image7 image8
mImage is the one i would like to swap with the rest, I can swap it only with the next one or with the one below(Sort of like a puzzler).
So the mImage can be swap only with image1 and image3.
What i thought is to swap with i+1 or with i+3 when the mouse is clicked.
Is that a good technique or is there a better approach to this problem?
Thank you
Solution
When an image is clicked, check if it's next to mImage
(i.e. either it's X coordinate is the same as mImage.X and the difference in Y coordinates is equal to 1, or the other way round). If it's true, then you can swap.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow