### help me change the color of piece in tetris

 ``1234567891011`` ``````void SetupPieces() { pieces[0] = Piece(Bads(0,2), Bads(0,1), Bads(0,0), Bads(0,-1)); pieces[1] = Piece(Bads(0,0), Bads(0,1), Bads(1,0), Bads(1,1)); pieces[2] = Piece(Bads(-1,0), Bads(0,0), Bads(1,0), Bads(0,-1)); pieces[3] = Piece(Bads(-1,1), Bads(-1,0), Bads(0,0), Bads(0,-1)); pieces[4] = Piece(Bads(1,1), Bads(1,0), Bads(0,0), Bads(0,-1)); pieces[5] = Piece(Bads(1,1), Bads(1,0), Bads(0,0), Bads(-1,0)); pieces[6] = Piece(Bads(-1,1), Bads(1,0), Bads(0,0), Bads(-1,0)); }``````
A tetris piece is a tetramino, which are 4 blocks connected into a figure. What you should do is spawn a figure, and make all of those blocks one color. You should use something like this.

 ``1234567891011121314151617181920`` ``````#include enum Colors{ black, // 0 text color - multiply by 16, for background colors dark_blue, // 1 dark_green, // 2 dark_cyan, // 3 dark_red, // 4 dark_magenta, // 5 dark_yellow, // 6 light_gray, // 7 dark_gray, // 8 light_blue, // 9 light_green, // 10 light_cyan, // 11 light_red, // 12 light_magenta, // 13 light_yellow, // 14 white // 15 };``````
We don't even know how you are creating your tetris. Are you using a library like sfml, sdl, opengel? So would be impossible for us to tell you how to change the color without making guesses.

I was able to compile your Tetris C++ program, using Dev-C++, but am unable to figure out exactly where you send the info to a function to draw the specified piece. If you can me know that location in the program, I should be able to color each shape a different for you.

THis is my code

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251`` ``````#include #include #include using std::cout; using std::endl; HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE); class Bads { public: Bads(int x = 0, int y = 0) : X(x), Y(y) { } int X, Y; Bads operator + (const Bads &right) const { return Bads(X + right.X, Y + right.Y); } }; const char *TITLE = "########## THE TETRIS ###########"; const char *SCORE_FILE = "c:\\tetrisScore.txt"; const char *FAIL_STR = "GAME OVER!"; const int FIELD_WIDTH = 14, FIELD_HEIGHT = 19; const int HORIZONTAL_DIVIDE = 4, VERTICAL_DIVIDE = 20; const int BOARD_WIDTH = 35, BOARD_HEIGHT = FIELD_HEIGHT + HORIZONTAL_DIVIDE + 1; const Bads FIELD_START((VERTICAL_DIVIDE - FIELD_WIDTH)/2,HORIZONTAL_DIVIDE + 1); const Bads NEXT_PIECE_POS(VERTICAL_DIVIDE + (BOARD_WIDTH - VERTICAL_DIVIDE)/2,HORIZONTAL_DIVIDE + 4); const Bads SCORE_POS(VERTICAL_DIVIDE + 2,NEXT_PIECE_POS.Y + 4); char field[FIELD_HEIGHT * FIELD_WIDTH]; bool exiting = false; bool downHeld = false; int score = 0, highScore = 0 ; void welcome (){ system("color b1"); cout<<"\n\n\n\t\t _____ _ _____ _____ (_) ___ \n"; system("color bd"); Sleep(200); cout<<"\t\t|_ _| |_ ___ |_ _|___|_ _|/\\_ _ ( _) \n"; system("color bc"); Sleep(200); cout<<"\t\t | | | ' \\/ -_) | | \/ -_) | | | __|| |_\\ \\ \n"; system("color b0"); Sleep(200); cout<<"\t\t |_| |_||_\\___| |_| \\___| |_| |_| |_|(___) \n\n"; system("color b1"); Sleep(200); cout<<"\t\t\tThe Tetris\n"; system("color b3"); Sleep(500); cout<<"\t\t\tby: John Singson \n"; system("color b1"); Sleep(500); cout<<"\t\t\tPress any key to continue. . ."; getch(); system("cls"); } void Reset(); char &GetField(const Bads &pos) { return field[pos.Y*FIELD_WIDTH + pos.X]; } char &GetField(int x, int y) { return field[y*FIELD_WIDTH + x]; } void SetConsoleCursor(const Bads &pos) { COORD c = {(short)pos.X, (short)pos.Y}; HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleCursorPosition( h, c ); } class Piece { public: Piece() { } Piece(const Bads &b1, const Bads &b2, const Bads &b3, const Bads &b4) { Blocks[0] = b1; Blocks[1] = b2; Blocks[2] = b3; Blocks[3] = b4; } void SetPosition(const Bads &pos) { Position = pos; } Bads &GetPosition() { return Position; } bool Step() { ++Position.Y; if (Collide()) { --Position.Y; Freeze(); return true; } return false; } void Rotate() { for (int i = 0; i < 4; ++i) { Bads pos = Blocks[i]; Blocks[i] = Bads(-pos.Y, pos.X); } if (Collide()) { UnRotate(); } } void UnRotate() { for (int i = 0; i < 4; ++i) { Bads pos = Blocks[i]; Blocks[i] = Bads(-pos.Y, pos.X); } } void Draw(const Bads &fieldStart, bool clamp = true, char character = 'O') { for (int i = 0; i < 4; ++i) { Bads pos = Position + Blocks[i]; if (pos.Y >= 0 || !clamp) { SetConsoleCursor(fieldStart + pos); cout<= FIELD_WIDTH || (pos.Y >= 0 && GetField(pos) == '#')) return true; } return false; } private: void Freeze() { for (int i = 0; i < 4; ++i) GetField(Position + Blocks[i]) = '#'; } Bads Position; Bads Blocks[6]; }; const int PIECE_COUNT = 7; Piece pieces[PIECE_COUNT]; Piece activePiece, nextPiece; void SetupPieces() { pieces[0] = Piece(Bads(0,2), Bads(0,1), Bads(0,0), Bads(0,-1)); pieces[1] = Piece(Bads(0,0), Bads(0,1), Bads(1,0), Bads(1,1)); pieces[2] = Piece(Bads(-1,0), Bads(0,0), Bads(1,0), Bads(0,-1)); pieces[3] = Piece(Bads(-1,1), Bads(-1,0), Bads(0,0), Bads(0,-1)); pieces[4] = Piece(Bads(1,1), Bads(1,0), Bads(0,0), Bads(0,-1)); pieces[5] = Piece(Bads(1,1), Bads(1,0), Bads(0,0), Bads(-1,0)); pieces[6] = Piece(Bads(-1,1), Bads(1,0), Bads(0,0), Bads(-1,0)); } int max(int a, int b) { return a>b ? a : b; } int RandInt(int low, int high) { int range = high - low; return low + rand() % range; } void LoadHighScore() { FILE *file = fopen(SCORE_FILE, "r"); if (file) { fscanf(file, "%i", &highScore); fclose(file); } } void SaveHighScore() { FILE *file = fopen(SCORE_FILE, "w"); if (file) { fprintf(file, "%i", highScore); fclose(file); } } void Fail() { int failLen = (int)strlen(FAIL_STR); Bads pos = FIELD_START + Bads((FIELD_WIDTH - failLen)/2,FIELD_HEIGHT/2); SetConsoleCursor(pos); cout< -100 && GetKeyState(VK_RETURN) > -100) {} highScore = max(highScore, score); SaveHighScore(); Reset(); }``````
part two of my code

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307`` ``````void SpawnPiece() { activePiece = nextPiece; activePiece.SetPosition(Bads(FIELD_WIDTH/2, 0)); if (activePiece.Collide()) { Fail(); return; } system("color b1"); nextPiece.UnDraw(NEXT_PIECE_POS, false); nextPiece = pieces[RandInt(0,PIECE_COUNT)]; nextPiece.Draw(NEXT_PIECE_POS, false); } void DrawStatics() { for (int i = 0; i < BOARD_WIDTH; ++i) { system("color 1b"); SetConsoleCursor(Bads(i,0)); cout<<'#'; SetConsoleCursor(Bads(i,BOARD_HEIGHT)); cout<<'#'; SetConsoleCursor(Bads(i,HORIZONTAL_DIVIDE)); cout<<'#'; } for (int i = 1; i < BOARD_HEIGHT; ++i) { system("color 1b"); SetConsoleCursor(Bads(0,i)); cout<<'#'; system("color 1c"); SetConsoleCursor(Bads(BOARD_WIDTH-1,i)); cout<<'#'; SetConsoleCursor(Bads(VERTICAL_DIVIDE,max(i, HORIZONTAL_DIVIDE+1))); cout<<'#'; } for (int i = 0; i < FIELD_HEIGHT; ++i) { system("color 1c"); SetConsoleCursor(FIELD_START + Bads(-1,i)); cout<<"#"; system("color 1d"); SetConsoleCursor(FIELD_START + Bads(FIELD_WIDTH,i)); cout<<"#"; } int len = (int)strlen(TITLE); Bads pos((BOARD_WIDTH - len)/2, HORIZONTAL_DIVIDE/2); SetConsoleCursor(pos); cout< 0) { CollapseBoard(rowStart, rowCnt); rowStart += rowCnt; rowCnt = 0; } else { ++rowStart; } } } if (rowCnt > 0) CollapseBoard(rowStart, rowCnt); } void DoLogic(int dt) { static int time = 0; time += dt; int stepRate = 200; if (time > stepRate ) { StepPiece(); time -= stepRate; } if (downHeld) StepPiece(); TestBoard(); } void Draw() { for(int y = 0; y < FIELD_HEIGHT; ++y) { SetConsoleCursor(FIELD_START + Bads(0,y)); for (int x = 0; x < FIELD_WIDTH; ++x) cout< GetTickCount()) ProcessInput(); } int main() { HANDLE hConsole; hConsole = GetStdHandle(STD_OUTPUT_HANDLE); { int z; int choice,choice1; welcome(); cout<<"\n Player : ";; scanf("%d", &choice); } LoadHighScore(); SetupPieces(); Reset(); while(!exiting) { int dt = 50; Delay(dt); ProcessInput(); DoLogic(dt); Draw(); } }``````