Skip to main content
gamedev.net
🔒 Locked

Queue to arrays

Started by honge 1 reply 500+ views
Original Post
honge
honge
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
LessBread
LessBread
It's not clear what you're trying to do.
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
Zahlman
Zahlman
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.