Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (595)
Games in Android Showcase (168)
games submitted by our members
Games in WIP (646)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Tetris help  (Read 931 times)
0 Members and 1 Guest are viewing this topic.
Offline adimanic

Junior Newbie

« Posted 2006-05-31 22:05:25 »

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:;5099742;;/fileinfo.html.

Knowing us, we probably made some really stupid mistakes.
Offline Kova

Senior Devvie

« Reply #1 - Posted 2006-05-31 23:49:06 »

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

Junior Newbie

« Reply #2 - Posted 2006-06-01 22:24:44 »

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.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline rdcarvallo

Senior Devvie

Projects: 5
Exp: 15 years

2D Java games forever!

« Reply #3 - Posted 2006-06-02 17:03:49 »

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

Offline adimanic

Junior Newbie

« Reply #4 - Posted 2006-06-02 20:15:07 »

Thanks, I know it's got loads of problems those were the big two at the moment. thanks again.
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

deepthought (49 views)
2015-06-30 15:39:44

deepthought (56 views)
2015-06-30 15:39:09

deepthought (65 views)
2015-06-30 15:36:52

Za\'Anzabar (43 views)
2015-06-29 05:44:54

TritonDreyja (49 views)
2015-06-24 17:10:40

CopyableCougar4 (49 views)
2015-06-23 00:34:45

BurntPizza (58 views)
2015-06-21 20:36:46

cookiecompiler (98 views)
2015-06-11 15:42:53

cookiecompiler (58 views)
2015-06-11 15:41:14

NegativeZero (81 views)
2015-06-11 09:49:18
How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21

Resources for WIP games
by kpars
2014-12-18 10:26:14 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!