Tetris (5)

  1. Modify your previous TETRIS program, so that the 7 tetrominoes are stored in a struct array, instead of two independet arrays.
  2. If you use an array max_x[7] to store the width of the 7 tetrominoes, try to replace it with a function max_x() to provide better flexibility. You'll need this when you want to rotate a tetromino.
  3. If your program is well structured, you only need to modify the draw_block() function and erase_block() function.
  4. Suppose you declare the struct as
    
    struct Square
    {
        int dx;
        int dy;
    };
    
    struct Tetromino
    {
        Square s[4];
    };
    
    Tetromino t[7] = {
                        0,0, 1,0, 2,0, 3,0 ,
                        0,0, 0,1, 1,1, 2,1 ,
                        0,1, 1,1, 2,1, 2,0 ,
                        0,0, 1,0, 0,1, 1,1 ,
                        0,1, 1,1, 1,0, 2,0 ,
                        0,1, 1,1, 1,0, 2,1 ,
                        0,0, 1,0, 1,1, 2,1
                     };
    
    
    You would be able to access the coordinate of Square j in Tetromino n as t[n].s[j].dy or t[n].s[j].dx.
  5. The program should run as the same as the previous one. In this exercise, we simply replace the data structure from two integer arrays to a struct array, so that it will be easier to support the features required in the next version.