I've got some ideas on how to stop the blocks but i do not know how to put them into codes. because moving to the left, i have to -cln so when the cln reach -1, i'll +1 to the cln again so that it remains at the same place. i've been racking my brains on this but still cant come up with the codes. I also need some help on the rotating.
Code:#include <stdio.h> #include <stdlib.h> #include <stdbool.h> #define ROW 15 #define COLUMN 15 void gameboard(char b[ROW][COLUMN]) { int r, c; for(r = -1; r <= ROW; r++) { for(c = -1; c <= COLUMN; c++) { if(r == -1 || r == ROW || c == -1 || c == COLUMN) { putchar('*'); putchar(' '); } else { putchar(b[r][c]); putchar(' '); } } putchar('\n'); } } void assignblocks(char b[ROW][COLUMN]) { int rol,col; srand( (unsigned) time(NULL)); for (col = 6;col<9;col++) { b[0][col] = rand()%2; if (b[0][col] == 1) { b[0][col]= 'X'; } } printf("\n"); for (col = 6;col<9;col++) { b[1][col] = rand()%2; if (b[1][col] == 1) { b[1][col]= 'X'; } } b[1][7]='X'; printf("\n"); for (col = 6;col<9;col++) { b[2][col] = rand()%2; if (b[2][col] == 1) { b[2][col] = 'X'; } } } void movement (char b[ROW][COLUMN]) { char input; int rw,cln; do { fflush(stdin); printf("\nEnter your next move: "); scanf("%c",&input); if (input == '4') { for (rw=0;rw<16;rw++) for (cln=0;cln<16;cln++) if (b[rw][cln] == 'X') { b[rw][cln-1]='X'; b[rw][cln]=' '; } } if (input == '6') for (rw=15;rw>-1;rw--) for (cln=15;cln>-1;cln--) if (b[rw][cln] == 'X') { b[rw][cln+1]='X'; b[rw][cln]=' '; } if (input == '8') for (rw=15;rw>-1;rw--) for (cln=15;cln>-1;cln--) if (b[rw][cln] == 'X') { b[rw+1][cln]='X'; b[rw][cln]=' '; } if (input == '2') { } }while(input != '2' && input != '4' && input != '6' && input != '8'); } int main(void) { char box[ROW][COLUMN]; char name[20] ="AAA" ; int x,y; bool end = false; printf("*************Tetris Game*************\n"); printf("Please Enter Player Name: "); scanf("%s", &name); printf("Player Name:%s\n", name); for(x=0; x<16; x++) { for(y=0; y<16; y++) { box[x][y] = ' '; } } assignblocks(box); do { printf("\n\n*************Tetris Game*************\n"); printf("Player Name:%s\n", name); gameboard(box); movement(box); }while (end == false); return 0; }