Public Group

Tetris Clone - Problem Deleting Rows

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

Recommended Posts

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 on other sites
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!

1. 1
2. 2
Rutin
19
3. 3
JoeJ
16
4. 4
5. 5

• 30
• 22
• 13
• 13
• 17
• Forum Statistics

• Total Topics
631700
• Total Posts
3001800
×