Tetris help

Hi, were making a tetris game for our class, but were having some trouble with stopping the blocks in the correct row(ex: with a certain code, the block stops one above the bottom of the array/board, but altering the code by one yield an out of bounds exception, and then deleting the rows at the correct time(it deletes the rows after every fall, not when the block is done falling). If anyone could shed some light on this it would be great. I put our code in a zip file you can get here: http://files.filefront.com/Tetriszip/;5099742;;/fileinfo.html.

Knowing us, we probably made some really stupid mistakes.

first, I get 403: forbidden when trying to download the file. Second, why zip something so small anyway… we’re (well mostly of us) are out of stone age…
basicly it’s probably some trivial logic mistake in the code… but we still need to see the code.

Ok, I have a link below for a different file hosting service, although I asked some otehrs and it downloaded fine, it’s at file factory now. As to why I put them in a zip, it was the quickest way to upload the files together, and I figured it’s not that much trouble to upload. Sorry about the download error before, if it helps I think the main problems are in the dropPieces and movePiece methods. Thanks.

http://www.filefactory.com/get/v3/f2.php?f=44b4cb

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.-

Thanks, I know it’s got loads of problems those were the big two at the moment. thanks again.