Help with Tetris Function
I''m creating a Tetris-clone in C++ using DirectDraw4. The main gameplay area consists of an array of integers 10x15 that will hold either a 1 or 0 to determine if that place if occupied.
I have created a function to test if a line is full, and then to clear the line, but I am having a problem thinking of a solution on how to lower the whole grid by one step. Heres an example:
0 0 0 0
0 0 1 0
1 1 1 0
1 1 1 1 <- I want to clear out this line
1 1 0 1
I call the function and it sets all the numbers to 0
0 0 0 0
0 0 1 0
1 1 1 0
0 0 0 0 <- Set to zero to clear out the line
1 1 0 1
Now my problem is how to lower all the numbers above the line so they fall down one step. I''m probably overlooking a really simple solution, but I keep getting stuck here. Thanks for any input.
Two for loops should solve your problem.
For example, if Lines[10][15] is an array of all of your lines, and ErasedRow is an integer specifiying the row you just cleared, you should be able to shift each row down by doing the following:
for (int i=ErasedRow; i>0; i--)
for (int j=0; j<15; j++)
Lines[i-1][j] = Lines[j];
Then you just need to clear your top row.
For example, if Lines[10][15] is an array of all of your lines, and ErasedRow is an integer specifiying the row you just cleared, you should be able to shift each row down by doing the following:
for (int i=ErasedRow; i>0; i--)
for (int j=0; j<15; j++)
Lines[i-1][j] = Lines[j];
Then you just need to clear your top row.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement