Public Group

# Need help with my logic

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

## Recommended Posts

Ok I'm having some problem with my Tetris game ( Using SDL ) Everything is working good, now the only thing that still bug my function that check if the player made a line, and the one to erase the line(s). The way it's work i use 2 table to store the square position. m_iSquare_X_Position m_iSquare_Y_Position And when the piece are placed i switch their position to 2 other table m_iSquare_Old_X_Position m_iSquare_Old_Y_Position And here is the code of the 2 function not working how it should. Sometime it will remove a line and when it's remove one, the square arent placed like they should, and sometime it won't just see that there is a line.
void CPiece::Check_Line()
{
int iLine = 0; // Number of pieces found on the Same Y as iTemp
int iTemp = 0; // The curent Y position of a pice being check.
int iNbLine = 0; // The number of line erased.

for (int i = 0; i < 4; i++) //Check 4 time, because you can do 4 lines in one shot
{
iLine = 0; // Set iLine to 0 because a new Y is gona be check.
for (int j = 0; j < iCompteurXY; j++)
{
iLine = 0; // Set iLine to 0 because a new Y is gona be check.
iTemp = m_iSquare_Old_Y_Position[j]; // the Y position to be check

for (int k = 0; k < iCompteurXY; k++) // For that check the y vs all the Y in the table
{
if ( iTemp == m_iSquare_Old_Y_Position[k] ) // If iTemp is the same than the piece Y position
{
iLine++;
}
}
if ( iLine = 10 ) // If iLine is = 10 mean that the player made a line
{
Clear_Line(iTemp); // Call the function that will erase the line
iNbLine++; // To know how much line the player made in 1 shot
}
}
}
}

void CPiece::Clear_Line(int iTemp)
{
int iTabTempX[200]; //Temp table for X position
int iTabTempY[200]; //Temp table for Y position

for (int i = 0; i < iCompteurXY; i++)  //Until i haven't pass all the table case used
{
if ( m_iSquare_Old_Y_Position != iTemp ) // if the number is different than the line to erase
{
if (m_iSquare_Old_Y_Position < iTemp ) // It's it's higher than the Y pos of the line
{
iTabTempX = m_iSquare_Old_X_Position;
iTabTempY = m_iSquare_Old_Y_Position + 20; //+20 to lower the position
}
else // else if it's under it stay here
{
iTabTempX = m_iSquare_Old_X_Position;
iTabTempY = m_iSquare_Old_Y_Position;
}

}
}
iCompteurXY-= 10; // for the 10 square removed

for ( int i = 0; i < iCompteurXY; i++) // Transfert the temp tables.
{
m_iSquare_Old_X_Position = iTabTempX;
m_iSquare_Old_Y_Position = iTabTempY;
}

}



##### Share on other sites
Just taking a quick glance and one of your if statements looks a little dodgy:

if ( iLine = 10 ) // If iLine is = 10 mean that the player made a line {	Clear_Line(iTemp); // Call the function that will erase the line	iNbLine++; // To know how much line the player made in 1 shot}

should be:
if ( iLine == 10 ) // Should be == for comparison{	Clear_Line(iTemp); // Call the function that will erase the line	iNbLine++; // To know how much line the player made in 1 shot}

Also you are setting iLine to be 0 twice, once outside the 2nd loop and then again just as it iterates...is that correct?

##### Share on other sites
Oh Jesus christ.... what a stupid mistake thank i didn't notice it.

Changed it, still buging, the square doens't erase corectly.

And for the 2 iLine = 0; the first one can be erased yes, it change nothing.

##### Share on other sites
Here is a SS of what's happening sometime.

http://img300.imageshack.us/img300/2437/bug0iz.jpg

I still don't see what's wrong with my logic

1. 1
2. 2
Rutin
18
3. 3
4. 4
5. 5

• 9
• 9
• 9
• 14
• 12
• ### Forum Statistics

• Total Topics
633300
• Total Posts
3011266
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!