View Single Post
Old May 23rd, 2006, 9:17 PM   #1
Eric the Red
Hobbyist Programmer
 
Eric the Red's Avatar
 
Join Date: Feb 2006
Posts: 214
Rep Power: 0 Eric the Red is an unknown quantity at this point
1 class, 1 problem = 1 big headache

So i'm working on this big project in java (tetris) and i came across this error which could effect my entire program. Anyone who has a pretty good understanding of java's classes (simple stuff i would think) should continue reading.

I've narrowed down my code just to show the main problem causing the error.

        class Tetris
        { 
            
            public SmallBox smBox [] [];

            public Tetris ()
            {
                SmallBox smBox [] [] = new SmallBox [xMax] [yMax];
            }

            public void dltLine (int y)
            {
             // temp removed
            }

            public void movePiece (int x)
            {
            // temp removed
            }
           
        }

        class Piece
        {

            public SmallBox smPiece [] [];
            public SmallBox smBox [] [];

            public Piece ()
            {
                SmallBox smPiece [] [] = new SmallBox [xPiece] [yPiece];

                for (int y = 0 ; y < 4 ; y++)
                {
                    //smPiece [x] [y] = -10;
                }
            }


            public void extractPiece ()   // this is used to take the piece from 'The Grid' and assign it back into the 'pieceGrid' (so that we can work with it)
            {
                boolean tempPiece = false;
                int tempX1 = 0, tempY1 = 0; // used to mark the first tetris block found on the main grid.
                for (int y = 0 ; y < yMax ; y++)
                {
                    for (int x = 0 ; x < xMax ; x++)
                    {
                        if (smBox [x] [y].getActive = true) // once we find a moving block on the grid that belongs to piece.. we mark it.
                        {
                            tempX1 = x; // marks x cord of moving block
                            tempY1 = y; // marks y cord of moving block

                            SearchStart:
                            for (int startY = tempY1 ; startY < yMax ; startY++) // runs through the vertical part of the main grid to top of grid
                            {
                                if (smBox [x] [startY].getActice  = true) // if the piece above the marked one is there we move to the left on the x-axis
                                {
                                    break SearchStart;
                                }
                            }
                        }
                    }
                }
            }
        }

The orange font is where the error occurs. Apparently, i can't use the
"smbox[][]" array from the tetris class. So how am I supposted to use it then?

One other thing, is it okay to use smBox[][] in both classes this way? or should i pass it in from main() to the class?
__________________
Death smiles at us all. All a man can do is smile back.
Eric the Red is offline   Reply With Quote