Error printing tetris blocks within the game map

I have been learning a little bit of C++ and decided to recreate a game ofTetris. The problem here is when I tried to display the tetris block within the game map itself. I'm not sure what was wrong and would appreciate if someone could help point out the error for me thanks.

/*==========================
* Tetris
*==========================
*/

#include<iostream>
#include<cstdlib>
#include<time.h>
#include<conio.h>

char Piece[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 },
},
},
};
enum eDirection { STOP, ROTATE, LEFT, RIGHT, HDOWN, SDOWN };
eDirection direction;
bool Quit = false;
int NewType = rand() % 6; // Random new Piece
int Rotate = rand() % 3; //Random rotation for new piece
int x, y; //Game Piece location
int width = 10, height = 20;
int Score;

void newPiece()
{
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
if (Piece[NewType][Rotate][i][j] != 0)
std::cout << "#";
}std::cout << std::endl;
}
}
void start()
{
x = width / 2;
y = 1;

}
void draw()
{

for (int i = 0; i < width + 3; i++) //top wall
std::cout << " ";
std::cout << std::endl;

for (int i = 0; i < height; i++)
{
for (int j = 0;j < width + 2; j++)
{
if (j == 0)
std::cout << "\xDB"; // left wall within height
if (i == y && j == x)
for (int k = 0; k < 4; k++)
{
for (int l = 0; l < 4; l++)
{
if (i == k + y && j == l + x && Piece[NewType][Rotate][i][j] == 0)
std::cout << " ";
else if (i == k + y && j == l + x && Piece[NewType][Rotate][i][j] != 0)
std::cout << "#";
}
}

if (j == width + 1)
std::cout << "\xDB"; // right wall within height
else
std::cout << " ";
}std::cout << std::endl;
}
for (int i = 0; i < width + 3; i++) // bottom wall
std::cout << "\xDB";
std::cout << std::endl;
}
void input()
{
if (_kbhit())
{
switch (_getch())
{
case 'w':
direction = ROTATE;
break;
case 'a':
direction = LEFT;
break;
case 's':
direction = SDOWN;
break;
case 'd':
direction = RIGHT;
break;
case ' ':
direction = HDOWN;
break;
case 'q':
Quit = true;
break;
}
}

}
void logic()
{

//key logic for eDirection
switch (direction)
{
case ROTATE:
if (Rotate != 3)
Rotate++;
else
Rotate = 0;
break;
case LEFT:
x--;
break;
case RIGHT:
x++;
break;
case SDOWN:
y += 2;
Score += 1;
break;
case HDOWN:
// calculate space between bottom and piece
// Place piece at bottom
// Score += 1*calculated
break;
}
}

int main()
{
draw();
return 0;
}
You cannot print the elements like so. I suggest that you have an screen array that you fill with all the elements you want to see and then always print the whole array.
Ahh I see, I wasn't thinking of that, Thanks!
Topic archived. No new replies allowed.