Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (553)
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 810 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: http://files.filefront.com/Tetriszip/;5099742;;/fileinfo.html.

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

Senior Member





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

http://www.filefactory.com/get/v3/f2.php?f=44b4cb
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline rdcarvallo

Senior Member


Projects: 5
Exp: 15 years


2D Java games forever!


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

Hello,
   Your code for drop pieces has some problems:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
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:
1  
2  
  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:
1  
2  
  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
1  
2  
3  
  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)
1  
2  
3  
  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.-
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.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

TehJavaDev (15 views)
2014-08-28 18:26:30

CopyableCougar4 (25 views)
2014-08-22 19:31:30

atombrot (38 views)
2014-08-19 09:29:53

Tekkerue (33 views)
2014-08-16 06:45:27

Tekkerue (32 views)
2014-08-16 06:22:17

Tekkerue (20 views)
2014-08-16 06:20:21

Tekkerue (29 views)
2014-08-16 06:12:11

Rayexar (66 views)
2014-08-11 02:49:23

BurntPizza (42 views)
2014-08-09 21:09:32

BurntPizza (34 views)
2014-08-08 02:01:56
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org 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‑gaming.org
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!