Breaking the code into objects
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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access