Public Group

#### Archived

This topic is now archived and is closed to further replies.

# Help with Tetris Function

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

## Recommended Posts

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.

##### Share on other sites
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.

##### Share on other sites
Ok, thanks a lot for your help.

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

• 14
• 30
• 13
• 11
• 11
• ### Forum Statistics

• Total Topics
631780
• Total Posts
3002314
×