I am currently trying to create a grid of multiple squares (Should be a minesweeper grid one day).
Now my solution of getting every mine a specific position is by using this loop:
for(int i = 0; i < cols; i++)
{
for(int j = 0; j < rows; j++)
{
mines[i][j].setCoordinates(xCounter, yCounter);
xCounter+=150;
}
yCounter+=150;
xCounter = 0;
}
now 150 should display the width or the height of one square because if one mine is on (0,0) the next should be on (minewidth,0) to fit nice and snuggly.
But now my question is, how can I be independend of this 150?
I got to this number by trying out which number makes the grid without spacing. But when I use a lower density device the images are smaller but the distance to each other would remain 150 pixels.
Now how can I get something generally to be independent of this constant?
First I thought I could use the .getWidth() method to get the width of the Bitmap that is stored in my "Mine" class. But this didn't work out so...
Has anyone got an idea to create a grid independent of which density the device has?