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