Sign in to follow this  
returnofjdub

Tetris Clone - Problem Deleting Rows

Recommended Posts

returnofjdub    163
I'm writing a Tetris game in C# and my function for deleting a full row isn't working correctly. I've stared at the code for hours and for the life of me I can't figure out what I'm doing wrong. Hopefully a fresh pair of eyes will help me solve my problem :)
        void CheckForFullLine()
        {
            bool gap = false;
            for (int y = 0; y < PlayfieldHeight; y++)
            {
                gap = false;
                for (int x = 0; x < PlayfieldWidth; x++)
                {
                    if (playfield[x, y].Color == Color.Black || playfield[x, y].FromCurrentShape)
                        gap = true;
                }

                if (!gap)
                {
                    for (int ny = y; ny > 0; ny--)
                    {
                        for (int nx = 0; nx < PlayfieldWidth; nx++)
                        {
                            playfield[nx, ny] = playfield[nx, ny - 1];
                        }
                    }
                }
            }
        }
So to go through my logic, I'm iterating through the playfield to discover a full row. If we go through an entire row and there's no gap, we start from the y position we left off, and from there going up we assign the current row to the row directly above it until we hit the top row. At least that's what I think I'm telling my computer. In practice it seems to be just deleting the full row and leaving a blank space there and nothing gets moved down. Anyone know what I'm doing wrong?

Share this post


Link to post
Share on other sites
returnofjdub    163
Figured it out. I was moving the grid correctly, but I wasn't updatin the Y coordinate in my Block structure (I store the X and Y in the blocks for the active blocks, and I forgot I used them for rendering in the grid, regardless of where they are in the array... d'oh!) The above code works fine if you're drawing going strictly off the array. All I had to do was add playfield[nx, ny].Y++; and everything was fine. Hooray!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this