A feature-rich terminal-based Tetris game built with C++ as the final project for the Basic Programming course at Shahid Beheshti University.
The project implements the core mechanics of Tetris along with additional gameplay features such as custom board sizes, multiple game modes, hold and upcoming pieces, save/load functionality, a leaderboard, themes, and sound.
Project type: University team project Course: Basic Programming Platform: Terminal / Console Language: C++
This project is a command-line implementation of Tetris designed to practice fundamental C++ programming concepts through a larger interactive application.
Instead of implementing only the basic falling-block mechanic, the project includes a complete menu-driven game experience with configurable games, persistent data, multiple difficulty modes, and terminal-based visual elements.
- Seven standard tetromino shapes
- Random piece generation
- Piece rotation
- Horizontal movement
- Vertical movement
- Hard drop
- Hold piece
- Upcoming-piece preview
- Collision detection
- Line completion and removal
- Score tracking
- Level progression
- Increasing game speed
- Game-over detection
The game provides:
- Quick Game
- Custom Game
Custom games allow the player to configure:
- Player name
- Board width
- Board height
- Game mode
Two gameplay modes are available:
- Classic
- Extreme
The custom game mode allows the player to select the board dimensions instead of being restricted to the standard board.
The implementation validates the entered dimensions before allocating the game board.
The supported ranges in the current implementation are:
- Width: 6–74
- Height: 15–45
The terminal interface displays information such as:
- Player name
- Score
- Level
- Cleared lines
- Elapsed time
- Current board
- Held tetromino
- Upcoming tetrominoes
- Keyboard controls
The game also uses ANSI terminal formatting and custom UI functions to create a colored and structured console interface.
The game includes local persistence features.
A game can be saved and later loaded through the game's menu system.
The project maintains a leaderboard using GameData.txt.
Leaderboard functionality includes:
- Reading saved game/player data
- Sorting leaderboard entries
- Displaying scores
This allows scores and game information to persist between executions.
The project includes WAV audio files:
Tetris.wav
Tetris2.wav
Credits.wav
The game uses the Windows multimedia API to play audio during gameplay and other parts of the application.
The project is implemented primarily in a single C++ source file:
Tetris.cpp
The code is organized into groups of functions responsible for different parts of the game.
The main game state is represented by structures including:
GameTetriminoElementOption
The Game structure stores information such as:
player
board dimensions
game mode
theme
score
level
line count
time
game-over state
upcoming pieces
board
The implementation contains separate generators for the seven tetromino types:
I
O
L
J
S
Z
T
New pieces are randomly generated and can be rotated before being placed into the game.
The game dynamically allocates memory for its board and for tetromino blocks.
Movement and collision checks are performed before modifying the board state.
Completed rows are detected and removed, with the rows above them shifted downward and the player's score updated.
A simplified game flow is:
Main Menu
│
├── New Game
│ │
│ ├── Quick Game
│ └── Custom Game
│
├── Load Game
│
├── Leaderboard
│
├── How To Play
│
├── About Us
│
└── Exit
During gameplay:
Generate Tetromino
│
▼
Place Piece
│
▼
Read Player Input
│
├── Move
├── Rotate
├── Hold
└── Hard Drop
│
▼
Fix Piece
│
▼
Check Completed Rows
│
▼
Update Score / Level
│
▼
Check Game Over
│
└── Continue
The game supports keyboard controls for:
| Action | Control |
|---|---|
| Move left | Left Arrow |
| Move right | Right Arrow |
| Move down | Down Arrow |
| Rotate | Up Arrow / mode-dependent rotation controls |
| Hard drop | Space |
| Pause | Esc |
The exact controls are also displayed inside the game interface.
| Technology | Purpose |
|---|---|
| C++ | Game implementation |
| Windows Console | Terminal interface |
| Windows Multimedia API | Audio playback |
| Standard C++ libraries | Core functionality |
| File I/O | Save/load and leaderboard |
No external game engine or third-party game framework is required.
This project was created to apply the fundamentals of C++ programming to a larger interactive system.
Concepts practiced include:
- Variables and data types
- Functions
- Structures
- Arrays
- Pointers
- Dynamic memory allocation
- Dynamic two-dimensional arrays
- File I/O
- Random number generation
- Input validation
- Control flow
- Recursion
- State management
- Collision detection
- Basic game-loop design
- Terminal manipulation
- Windows-specific APIs
Tetris-Clone/
├── Tetris.cpp
├── GameData.txt
├── Tetris.wav
├── Tetris2.wav
├── Credits.wav
└── README.md
GameData.txt is used by the game for persistent game/leaderboard data.
The original project uses the Windows multimedia library for audio playback.
The repository's original build command is:
g++ .\Tetris.cpp -o "Tetris" -lwinmm
The -lwinmm linker option is required for the Windows multimedia functionality used by the project.
The game is therefore intended primarily for a Windows environment.
This project was developed as the final project of the Basic Programming course at Shahid Beheshti University.
It was developed as a team project by:
- Ali Taherzadeh
- Sajjad
The project was created during an early stage of learning C++ and software development, before the widespread use of AI-assisted programming tools.
The goal was to apply basic programming concepts to a relatively large interactive program rather than to create a production-level game engine.
Although the project contains a substantial number of features, it should be understood as an educational console-game project.
It was primarily intended to practice:
C++ fundamentals → memory management → file handling → interactive program design → game logic
rather than modern game-engine development.
This is an educational implementation inspired by the classic Tetris game.
It is not affiliated with or endorsed by The Tetris Company.
No license has been specified for this project.