OK, if i was making something like a sliding puzzle game. Im sure most if not all of you are aware of what such thing is:
if not, its a tile game of an image usually of 3x3 size, and the tiles are randomized and the player has to put the pieces in order. To make it look like the original picture.
Anyway, how would I go about defining how the order should be? What I mean is, its obvious to win, you need all the right pieces in the right order, but how would you define that order, considering the game started off randomized and in no such order?
Is there a simple way of defining in which order these pieces need to be in the grid to activate a win screen?
Any links toward making this happen, or a few sentences would suffice, not looking for code, just a instruction list so to speak.
Thanks in advance.
hm. I guess one way to go about it would be to define 2 arrays or lists - some kind of ordered collections.
One holds the correct sequence of pieces, from top left to bottom right - like you read a page.
The other holds the current sequence of the pieces.
Whenever the player completes a move/switch of the pieces, you simply check if each piece of the last collection is equal to the piece in the corresponding index of the first collection. If they are all equal, the puzzle is complete!
Good luck!
I thought that may be the answer, but was not sure if it was possible.
Thanks Tobias.
I think all the answers involve some internal order and another on screen order. I can think of a few other ways:
Arbitrarily assign a number to each position, and assign that number to each representation of a tile, and check the tile’s current position to its “correct” position every move. (Literally just comparing 2 variables a tile holds)
If you really want to go crazy, you can have each tile save a reference to what other tiles are suppose to be on each side, and then check against all adjacent tiles every move. This, I believe, primary works for non-uniform tiling (if any given tile can have a variable number of tiles on any given side), but you can try it.
Heading into ludicrous territory, I once designed a tiling game where you could win even if you constructed the picture upside-down or flipped backwards. As a novelty I assigned each tile a number such that the result made up a modified magic square (where each column and row added up to the same sum, but I had no restrictions where the squares had to be made of numbers had to be sequential) then checked for the magic square’s completion every move. It was kinda pointless, and was more of a mathematical joke than anything else, but it worked.
As to the question of starting off a game randomized…just start it off in order, record the order first, then randomize it? Not sure if that’s what you’re looking for.