Need help with tetris game

Started by
14 comments, last by BrasiLokau 17 years, 11 months ago
Hello everyone, I'm making a tetris game and i'm having a really hard time to implement a row completion check. I have a Block class and a Shape class that inherits Block, and each different shape type inherits Shape. When a certain shape reaches the bottom I add it to an ArrayList called al_settledShapes. I'm making it based on the tutorial at c-unit.com, its not exactly that way, but the structure of the classes is pretty much the same, also my version is in SdlDotNet. Here's what i've been trying to do:

        public void CheckRowCompletion()
        {
            int completedCols = 0;
            int rowPosition = 0;
            ArrayList rowsToRemove = new ArrayList();

            for (int row = 0; row < num_rows; row++)
            {
                rowPosition = i_bottomBorder - row * (Block.i_blockWidth + 1);

                foreach (Shape s in al_settledShapes)
                {
                    foreach (Block b in s.Blocks)
                    {
                        if (b.Active && (b.Y == rowPosition))
                        {
                            completedCols++;
                            if (completedCols == num_cols)
                            {
                                i_score++;
                                //remove row
                                completedCols = 0;
                            }
                        }
                    }
                }
            }
        }
Really can't figure out why is not working Thanks in advance...
blog: www.brasilokau.com/games/blog
Advertisement
How about a simple array, with as many elements as you have rows

Every time a block in a certain row is placed, add one and when it reaches the amount of blocks per row, it will be completed

JUST-CODE-IT.NETManaged DirectX & C# TutorialsForumsArticlesLinksSamples
Well that would be "ANOTHER" way of doing it... but i already have my project pretty far, i want to do it the way i'm doing it...
Can someone help-me out with this? its a logic problem, so if you'd give me examples in other languages or explain to me what im doing wrong would be great.

Thanks
blog: www.brasilokau.com/games/blog
You should tell us exactly what is going wrong. When the code runs what happens? does nothing happen or do you get some other unexpected result.
Simplicity is the ultimate sophistication. – Leonardo da Vinci
Sorry about that, didn't notice, i actually didn't explain what the problem was. The problem is that NOTHING happens, i just increase the score counter to check if it worked but it didn't... hope somebody can come up with a solution

thanks
blog: www.brasilokau.com/games/blog
Quote:Original post by BrasiLokau
I have a Block class

What is the purpose of this class? How does its interface look like?

Quote:Original post by BrasiLokau
and a Shape class that inherits Block

What is the purpose of this class? How does its interface look like?

Quote:Original post by BrasiLokau
and each different shape type inherits Shape.

You mean you have seven different Shape classes? How do they differ in behavior?
Quote:Original post by BrasiLokau
if (b.Active && (b.Y == rowPosition))
{
completedCols++;
if (completedCols == num_cols)
{
i_score++;
//remove row
completedCols = 0;
}
}...


This section here is supposed to remove your row? As far as I can see it is only resetting a variable to 0. How is this removing a row? Sorry, hard to guess without knowing what your other code is doing.
SDBradley
CGP
"A person who won't read has no advantage over one who can't read." ~Mark Twain
IronGryphon:

I think the comment is supposed to be a placeholder and the fact that the score isn't increated shows that it doesn't work.

BrasiLokau:

My suggestion is: rename the variables and write comments so that anybody can understand what is supposed to happen ... and to prove that you understand the code.
Maybe by doing that you'll stumble over the error.

Also create a logfile class that shows which parts of the code get executed and what doesn't ... or use the debug mode to "step through the code".
I usually work with a logfile so I can't explain how working with the debugger is done properly.
Writing errors since 10/25/2003 2:25:56 AM
omg... i found the stupid mistake i made... it was that a block when reaches the bottom, its Y value is greater than the value i was checking to see when the block reaches the bottom. Pretty weird problem... working on a fix...

Sorry about that guys, thanks a lot
blog: www.brasilokau.com/games/blog
Btw, there is another error that will lead to problems. You reset "CompletedCols=0" only when you happen to find a completed row. This is wrong, because if a row is only half-complete, you will start the check of the next row with CompletedCols>0. You must reset CompletedCols in every iteration.

This topic is closed to new replies.

Advertisement