playMaker

Author Topic: Help with Arrays and making a puzzle game  (Read 1058 times)

Sonicjoy

  • Playmaker Newbie
  • *
  • Posts: 1
Help with Arrays and making a puzzle game
« on: September 03, 2018, 12:22:23 AM »
I'm trying to make a puzzle scene in my adventure game that's a 4 x 4 grid of game objects that get mixed randomly on start and need to be rearranged back to the correct order during gameplay. I figure I should best accomplish this with 2 Game Object arrays: Array1 has the Game Objects in the correct order and Array2 is used to store the current order of the object on the grid. Then as the player moves the game objects, I should compare Array1 to Array2 to see if they're exact.

Does anyone have any advice on creating this? I'm new to arrays and just starting to program this puzzle scene so any help/suggestions or tutorials that I could be pointed to would be much appreciated!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Help with Arrays and making a puzzle game
« Reply #1 on: September 03, 2018, 03:04:34 AM »
Hi,

 I would not use array but instead hashtable.

 the key would represent the x and y grid position

"x_y", "piece ID"

so, you have then one hashtable representing the solved puzzle and one that represent the current state.

checking if the user solved it, means you simply go through each grid position and compare the values for the same key on both hashtable, as soon as it doesn't match, the user has not solved the puzzle.

Does that make sense?

you can also totally get away with a single string, where the position of each character represents a grid cell and the character itself the type of piece on that grid cell.

Since you never want to deduce a grid cell but always want to read the data knowing the grid cell, you can really optimize your data ( some would go all the way and have a bytearray if it was in pure c#)


 Bye,

 Jean