Hello,
Your code for drop pieces has some problems:
public void dropPieces(){//Start dropPieces method
for (int i=numRows-1;i>=0;i++){//Start for
for (int k=numCols-1;k>=0;k++){//Start nested for
if ((TetrisBoard[i][k].getFilled()== true) && (TetrisBoard[i+1][k].getFilled()==false)){//Start if
TetrisBoard[i][k].unsetBlock();
TetrisBoard[i+1][k].setBlock();
}//End if
}//End nested for
}//End for
}//End dropPieces method
First you have a loop that needs to decrement from numRows-1 to 0, but you have an increment operator:
for (int i=numRows-1;i>=0;i++){//Start for
for (int k=numCols-1;k>=0;k++){//Start nested for
So, to correct this you must use:
for (int i=numRows-1;i>=0;i--){//Start for
for (int k=numCols-1;k>=0;k--){//Start nested for
Second, the index out of bounds is produced by using the value i = numRows -1 and indexing the array with i+1
for (int i=numRows-1;i>=0;i++){//Start for
for (int k=numCols-1;k>=0;k++){//Start nested for
if ((TetrisBoard[i][k].getFilled()== true) && (TetrisBoard[i+1][k].getFilled()==false)){//Start if
To solve this you should begin from the second row (the first doesn’t fall)
for (int i=numRows-2;i>=0;i--){//Start for
for (int k=numCols-1;k>=0;k--){//Start nested for
if ((TetrisBoard[i][k].getFilled()== true) && (TetrisBoard[i+1][k].getFilled()==false)){//Start if
Now the game has others problems but this helps you with your question.
Rafael.-