Jump to content
  • Advertisement
Sign in to follow this  
honge

Queue to arrays

This topic is 4863 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, just having a nightmare working out how to achieve something that i am sure is possible, figured you guys might have some ideas. Basically i am reading in a file and storing each character inside a Queue data structure. Then i decided i needed to be able to fill my game grid with all these values one by one. But instead of using a straightforward 2d array i am using a 2d array filled with classes that i call subGrids. Each of these subGrids has another 2d array inside it. Cant seem to be able to move between the right grids and columns ad rows to fill all of it in. At the moment i am trying using nested for loops but cant seem to get it right. e.g: This is how the overall grid looks with the number showing the different subGrids. --- --- --- --- --- --- --- --- --- | 1 | 1 | 1 | 2 | 2 | 2 | 3 | 3 | 3 | --- --- --- --- --- --- --- --- --- | 1 | 1 | 1 | 2 | 2 | 2 | 3 | 3 | 3 | --- --- --- --- --- --- --- --- --- | 1 | 1 | 1 | 2 | 2 | 2 | 3 | 3 | 3 | --- --- --- --- --- --- --- --- --- | 4 | 4 | 4 | 5 | 5 | 5 | 6 | 6 | 6 | --- --- --- --- --- --- --- --- --- | 4 | 4 | 4 | 5 | 5 | 5 | 6 | 6 | 6 | --- --- --- --- --- --- --- --- --- | 4 | 4 | 4 | 5 | 5 | 5 | 6 | 6 | 6 | --- --- --- --- --- --- --- --- --- Then the Queue holds for example: 0040090010605306400450002015 etc Any help greatly appreciated. Thanks

Share this post


Link to post
Share on other sites
Advertisement
I think he wants a mapping from (queue position) to (row, column).

Breaking it down:

queue position / square area gives you which square you are in.
queue position % square area gives you the position within each square.

From the position in the square, you can similarly get row and column within the square.

From which square you are in, you can similarly get a "row and column" for the grid of subgrids.

The final row is the subgrid row * subgrid width + within-subgrid row.
Similarly the column.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!