Jump to content
  • Advertisement
Sign in to follow this  
BrasiLokau

Need help with tetris game

This topic is 4414 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!