Process of how the game runs:
- A 10 x 20 board is created along with the different types of Tetrominoes (Pieces).
- A random piece is then generated to spawn at the top middle of the board and slowly fall.
- Each Piece can be moved to the right, left, down or rotated.
- As each piece is moved in any of the previously stated directions, it is undrawn from the previous and then redrawn after the move.
- If the Piece hits a wall or another Piece that has already fallen: That Piece is then locked into place and three scenarios can happen:
- The Piece could go past the top row and result in game over.
- The Piece can fill up a row and the row must be cleared and all above rows must be moved downward. In this case, the score must be changed.
- The Piece can be locked into position without clearing a line.
- Step 3 is repeated until game over.
For a more in concrete explanation, there are comments on the JavaScript code explanining how the code works.