Tetris Help v2

I am trying to start a project that makes the game, Tetris. For this part, I already have seven unique 2-dimensional arrays that will represent Tetriminos (Tetris pieces), and I need help to create two functions to rotate those 2-dimensional arrays: rotateLeft() and rotateRight(). It will rotate 90 degrees in the specified direction. E.g. RotateLeft() would move row 1 values to col 1; row 2 to row 2; etc. And to have a function called printTetrimino to print the contents of a 2-d tetrimino array to the console window. I am just having problems on how to finish the rotateRight function and to start on the rotateLeft function. And for this project, I would like to not use classes and vectors. Please let me know how to do this. Thank you! Code is below.

[code]
#include <iostream>

using namespace std;

// function implementations
void rotateRight();

int main() {

};

int tetromino[7][4][4][4] =
{
// Square piece
{
{
{ 1,1,0,0 },
{ 1,1,0,0 },
{ 0,0,0,0 },
{ 0,0,0,0 },
},
{
{ 1, 1, 0, 0 },
{ 1,1,0,0 },
{ 0,0,0,0 },
{ 0,0,0,0 },
},
{
{ 1,1,0,0 },
{ 1,1,0,0 },
{ 0,0,0,0 },
{ 0,0,0,0 },
},
{
{ 1,1,0,0 },
{ 1,1,0,0 },
{ 0,0,0,0 },
{ 0,0,0,0 },
},
},
// I piece
{
{
{ 1,1,1,1 },
{ 0,0,0,0 },
{ 0,0,0,0 },
{ 0,0,0,0 },
},
{
{ 1, 0, 0, 0 },
{ 1,0,0,0 },
{ 1,0,0,0 },
{ 1,0,0,0 },
},
{
{ 1,1,1,1 },
{ 0,0,0,0 },
{ 0,0,0,0 },
{ 0,0,0,0 },
},
{
{ 1,0,0,0 },
{ 1,0,0,0 },
{ 1,0,0,0 },
{ 1,0,0,0 },
},
},
// L piece
{
{
{ 1,0,0,0 },
{ 1,0,0,0 },
{ 1,1,0,0 },
{ 0,0,0,0 },
},
{
{ 1,1,1,0 },
{ 1,0,0,0 },
{ 0,0,0,0 },
{ 0,0,0,0 },
},
{
{ 1,1,0,0 },
{ 0,1,0,0 },
{ 0,1,0,0 },
{ 0,0,0,0 },
},
{
{ 0,0,1,0 },
{ 1,1,1,0 },
{ 0,0,0,0 },
{ 0,0,0,0 },
},
},
// J piece
{
{
{ 0,1,0,0 },
{ 0,1,0,0 },
{ 1,1,0,0 },
{ 0,0,0,0 },
},
{
{ 1,0,0,0 },
{ 1,1,1,0 },
{ 0,0,0,0 },
{ 0,0,0,0 },
},
{
{ 1,1,0,0 },
{ 1,0,0,0 },
{ 1,0,0,0 },
{ 0,0,0,0 },
},
{
{ 1,1,1,0 },
{ 0,0,1,0 },
{ 0,0,0,0 },
{ 0,0,0,0 },
},
},
// S piece
{
{
{ 0,1,1,0 },
{ 1,1,0,0 },
{ 0,0,0,0 },
{ 0,0,0,0 },
},
{
{ 1,0,0,0 },
{ 1,1,0,0 },
{ 0,1,0,0 },
{ 0,0,0,0 },
},
{
{ 0,1,1,0 },
{ 1,1,0,0 },
{ 0,0,0,0 },
{ 0,0,0,0 },
},
{
{ 1,0,0,0 },
{ 1,1,0,0 },
{ 0,1,0,0 },
{ 0,0,0,0 },
},
},
// N piece
{
{
{ 0,1,0,0 },
{ 1,1,0,0 },
{ 1,0,0,0 },
{ 0,0,0,0 },
},
{
{ 1,1,0,0 },
{ 0,1,1,0 },
{ 0,0,0,0 },
{ 0,0,0,0 },
},
{
{ 0,1,0,0 },
{ 1,1,0,0 },
{ 1,0,0,0 },
{ 0,0,0,0 },
},
{
{ 1,1,0,0 },
{ 0,1,1,0 },
{ 0,0,0,0 },
{ 0,0,0,0 },
},
},
// T piece
{
{
{ 1,0,0,0 },
{ 1,1,0,0 },
{ 1,0,0,0 },
{ 0,0,0,0 },
},
{
{ 1,1,1,0 },
{ 0,1,0,0 },
{ 0,0,0,0 },
{ 0,0,0,0 },
},
{
{ 0,1,0,0 },
{ 1,1,0,0 },
{ 0,1,0,0 },
{ 0,0,0,0 },
},
{
{ 0,1,0,0 },
{ 1,1,1,0 },
{ 0,0,0,0 },
{ 0,0,0,0 },
},
},
};

void rotateRight() {
for (int i = 0; i < 16; i++) {
int temp = tetromino[i][0];
tetromino[i][0] = tetromino[i][1];
tetromino[i][1] = -temp;
}
}
[code]
Last edited on
Topic archived. No new replies allowed.