The easiest way is to have an array that represnts the game area. each element of the array will be a square. Then have values for the array elements that represent the different states a square can be.
Typically
0 = blank square
1 = moving square
2 = stationary square
Then just have a function that draws a representation of the array to the screen, Just paste a copy of the square image where there is a 1 or 2.
A function that moves all 1s down until the shape hits the bottom or a stationary square(2).
A function that checks for completed lines and removes them as well as moving all squares above the completed line down.
A function that checks to see if there are no moving squares(1) and if there are none spawns a new piece at the top.