C++ was designed around an object-oriented paradigm, which is what the Tetris code base uses to simplify management of the application. The code base consists of C++ class files
(.cpp) and header files (.h) that represent objects within the context of the game. I used the gameplay summary from the What is Tetris? section to extrapolate which objects I needed.
The game pieces (Tetriminos) and playing field (referred to as a well or matrix) are good candidates for classes. Maybe less intuitively, but still just as valid, is the game itself. Classes don't necessarily need to be as concrete as actual objects — they're excellent for storing shared code. I'm a big fan of less typing, so I opted to use Piece to represent a Tetrimino and Board for the playing field (although the word well is shorter, it just doesn't quite fit). I created a header file to store global variables (constants.h), a Game class to manage gameplay, and a main.cpp file, which acts as the entry point for the game. Here's the contents of the /src folder:
├── board.cpp
├── board.h
├── constants.h
├── game.cpp
├── game.h
├── main.cpp
├── piece.cpp
└── piece.h
Each file (with the exception of main.cpp and constants.h) has a class (.cpp) and header (.h) file. Header files allow you to reuse code across multiple files and prevent code duplication. The Further reading section contains resources for you to learn more about header files if you're interested. The constants.h file is used in almost all of the other files within the application, so let's review that first.