A polished, feature-rich Tetris® clone for the Windows console, written in modern C++.
Created by n0m4official
- Classic Tetris gameplay — 7 standard tetrominoes, line clearing, scoring, and leveling.
- Modern Tetris enhancements:
- Ghost Piece — Preview exactly where your piece will land.
- Hold Piece — Swap the current piece for later use, with a visually displayed hold box.
- Next Piece Preview — See which tetromino comes up next, in a colored box.
- Colorful, Centered Console UI:
- Full ANSI color support for each piece.
- Board, next, and hold boxes are dynamically centered in your console window.
- Flicker-minimized drawing using Windows console APIs.
- Menus & User Experience:
- Start menu with controls and animated prompt.
- Pause menu with dimmed-out board and resume/quit options.
- Game over and exit screens, all with stylish, centered, colored text.
- Responsive Controls:
- Non-blocking input (move, rotate, drop, hold, pause, quit) — no waiting between moves!
- Classic Scoring & Levels:
- Scoring matches the original NES Tetris (single, double, triple, Tetris).
- Level increases every 10 lines, speeding up the game.
- Well-Commented, Modular Source Code:
- Designed for readability, learning, and extension.
In-game: Board, next, and hold preview
| Key | Action |
|---|---|
| A/D | Move left/right |
| W | Rotate piece |
| S | Soft drop (move piece down) |
| Space | Hard drop (instantly drop piece) |
| C | Hold current piece / swap with hold box |
| P | Pause / Resume |
| Q | Quit (from game or pause menu) |
| R | Restart (from game over menu) |
- Windows OS (uses Windows Console API and
<conio.h>) - A C++ compiler (Visual Studio recommended)
-
Clone this repo:
git clone https://github.com/n0m4official/CPP-Tetris.git cd CPP-Tetris -
Build
main.cpp:- Using Visual Studio:
Open the folder and build the project. - Using g++ (MinGW):
g++ main.cpp -o Tetris.exe -std=c++17 -static -luser32 -lkernel32
- Using Visual Studio:
-
Run:
./Tetris.exe
- main.cpp — All game logic, board, input, drawing, and menus in one modular, well-documented file.
Key modules & functions:
Boardclass: Board state, collision, line clearing, scoring.- Tetrominoes: 7-piece system, rotation, spawn, ghost calculation.
- Menus: Start, pause (with dim effect!), game over, ragequit.
- Drawing: Board, next, hold, and interactive text, all centered using Windows console API.
- Input: Non-blocking keyboard handling for smooth gameplay.
- Console UI polish:
Dynamically centers the game in your console, uses real ANSI color, and avoids flicker. - Modern gameplay:
Ghost piece + hold functionality + next preview — rare for console Tetris! - Menus and prompt animations:
Start, pause, and end menus with visually pleasing, interactive prompts. - Commented and maintainable:
Source code is full of helpful, honest comments for easier learning and extension.
loadColorsuses the literal condition1 < 7in its loop, so the index climbs indefinitely ifcolors.cfghas more than seven lines, causing out-of-bounds writes toCOLORS.Highscores.cpprelies onstd::numeric_limitswithout including<limits>, which breaks standalone builds of that translation unit.- The game accepts 10-character player names on game-over entry, but
loadHighscorestruncates every stored name to three characters when reloading from disk.
Tetris® is a registered trademark of The Tetris Company.
This project is a fan-made clone for educational purposes only and is not affiliated with or endorsed by The Tetris Company.
Have fun! Feel free to open issues or PRs for suggestions, bug fixes, or new features!


