• Advertisement
Sign in to follow this  

Creating a Grid Data Structure

This topic is 875 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

I am new to programming and game development. 

I am trying to make a game that has a grid. At any time, some of the locations in the grid may be occupied by a tile.

 

I am currently using a 2D Array, but for some reason it doesn't feel very OO. Not to mention accessing each element with nested for loops is making the code look really ugly. 

 

Should I continue with using the 2D Array, or is there another data structure that I should look in to? 

 

Thanks for taking the time. 

Share this post


Link to post
Share on other sites
Advertisement
Not to mention accessing each element with nested for loops is making the code look really ugly.

Well you colud convert from coord-to-index and when needed from index-to-coord in order to loop trough all cells via a single loop (this is what I'm doing right now).
 

I am currently using a 2D Array, but for some reason it doesn't feel very OO.

It's OO just enough. And keep in mind that in some point you will probably deciede that you need a few more variable that revolve around the "game board"(the 2D array), and well... there you go, the rest of the OO "package"

Share this post


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

  • Advertisement