Sign in to follow this  

Brick game question

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

Hi all, I am doing a game similar to brick game.But i am having problem as to how do i match similar tiles. I have stored the map in a one-dimension array GameWorld .game map is 6x12. each tile will have data as to wat is stored in the tile. if it has a red tile,or blue tile or is empty. Can anyone give me a idea on how can i best check for matching tile horizontally,vertically and both. thank you very much. Glen

Share this post


Link to post
Share on other sites
So basically, you're storing a 2D grid in a 1D array, right? If so, why a 1D array and not a 2D?

If, for some reason, you want to stick to the 1D array, then I would write an accessor function for it that takes a x and y coordinate and returns the value located at that point:

int GetTile(int x, int y)
{
return array[x + y * width];
}

So, when working with a 2D array, you'd access items with array[x][y], and if you use the above function, the 1D approach isn't much different: GetTile(x, y).

From there, you'd simply call every element in a row or in a collumn and compare them to each other. Just compare each element to the next one: if one differs, then you know for sure not all elements in that row or collumn are the same, and you stop testing already.

Share this post


Link to post
Share on other sites

This topic is 3857 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this