Ok, I got a 2d array where they are filled with certain letter. So, I need to remove any location that has the letter "X" and replace it with whatever is above.
Here what the 2D array would start out as. Notice that there are Xs in Row 12-14 that needs to be removed with whatever is above it:
Code:
A B C D E F G H I J K L M
1 X X X X X X X X X X X X X
2 X X X X X X X X X X X X X
3 X X X X X X X X X X X X X
4 X X X X X X X X X X X X X
5 X X X X X X X X X X X X X
6 X X X X X X X X X X X X X
7 X X X X X X X X X X X X X
8 X X X X X X X X X X X X X
9 X X X X X X X X X X X X X
10 Y Y G Y G Y R G G G R G G
11 R R Y R G G R R Y G Y R Y
12 X Y R R R Y R R G Y R G G
13 X X R R R R Y R G R Y Y R
14 X X Y G Y R G R R Y R Y Y
15 R Y Y R G G G Y R R R G Y
Here is what I need to end up with after running the method:
Code:
A B C D E F G H I J K L M
1 X X X X X X X X X X X X X
2 X X X X X X X X X X X X X
3 X X X X X X X X X X X X X
4 X X X X X X X X X X X X X
5 X X X X X X X X X X X X X
6 X X X X X X X X X X X X X
7 X X X X X X X X X X X X X
8 X X X X X X X X X X X X X
9 X X X X X X X X X X X X X
10 X X G Y G Y R G G G R G G
11 X X Y R G G R R Y G Y R Y
12 X Y R R R Y R R G Y R G G
13 Y R R R R R Y R G R Y Y R
14 R Y Y G Y R G R R Y R Y Y
15 R Y Y R G G G Y R R R G Y
But here's what actually happens:
Code:
A B C D E F G H I J K L M
1 X X X X X X X X X X X X X
2 X X X X X X X X X X X X X
3 X X X X X X X X X X X X X
4 X X X X X X X X X X X X X
5 X X X X X X X X X X X X X
6 X X X X X X X X X X X X X
7 X X X X X X X X X X X X X
8 X X X X X X X X X X X X X
9 X X X X X X X X X X X X X
10 X X G Y G Y R G G G R G G
11 Y Y Y R G G R R Y G Y R Y
12 R R R R R Y R R G Y R G G
13 X Y R R R R Y R G R Y Y R
14 X X Y G Y R G R R Y R Y Y
15 R Y Y R G G G Y R R R G Y
It seems to me that everytime the method is suppose to replace X in a specific row, it's actually doing the row above.
Code:
private void collapseRow() {
for(int i = ROW_LIMITS; i > 0; i--) {
for(int j = COLUMN_LIMITS; j > 0; j--) {
if(grid[i][j] == "X") {
if(i - 1 >= 1) {
grid[i][j] = grid[i - 1][j];
grid[i - 1][j] = "X";
}
}
}
}
}