I am trying to make a Tetris game. I finished everything so far, except the rotation function. So, to sum it up. The plan is to rotate the following array elements by 90°: (In this case its a bool array)
. . . . . . . . . .
. . x . . . . . . .
. . x x . ====== > . . x x .
. . . x . . x x . .
. . . . . . . . . .
To do this I wrote the following code:
private bool[,] rotateGrid(bool[,] _grid)
{
bool[,] g = new bool[5, 5];
for(int i=0; i<5; i++)
{
bool[] row = new bool[5];
for(int j=4; j>=0; j--)
{
int jInvert = 4 - j;
row[jInvert] = grid[j, i];
}
for(int j=0; j<5; j++)
{
grid[i, j] = row[j];
}
}
return g;
}
somehow, if I call this function with a full array, it retunes a empty one.
Why?