I'm currently creating a brickbreaker (or breakout, like atari breakout) and for the bricks im using a 2d array:
private Brick bricks[][] = new Brick[10][41];
To destroy a specific Brick (for whatever reason i have to destroy that), i created a method:
public void destroyBrick(Brick brick) {
for(int x = 0; x < bricks[x].length; x++) {
for(int y = 0; y < bricks[y].length; y++) {
if (bricks[x][y].equals(brick)) {
bricks[x][y] = null;
}
}
}
}
The way the array is created is the following:
for(int j=0; j<bricks[0].length; j++){
for(int i=0; i<bricks.length; i++){
bricks[i][j]=new Brick(game,10,Color.GREEN,j*margin,i*margin);
}
}
Now for some reason the counter for x eventually reaches 10 and the counter for y reaches 0 where it crashes, and i can't figure out why.
Is there a different way of iterating a 2d array that has different values for columns and rows?
note The reason the formatting and my spelling is so rubbish is, that im writing this on the app version. Feel free to correct any mistakes or formatting errors, before i can.