- 🔥 Overview
- ✨ Features
- 🎮 Controls
- 🕹️ Game Mechanics
- 💡 Code Structure & OOP Concepts
- ⚙️ Technical Details
- 🛠️ Installation & Execution
- 📁 Project Structure
- 🚀 Why Play This Tetris?
- 🤝 Collaborators
- 📢 Share & Support
- 🤝 Contributing
Welcome to the Tetris Game developed as part of the IT206 - Data Structures Lab at DA-IICT. This project implements a console-based version of the classic Tetris game using C++ and leverages various data structures and algorithms to manage game logic and rendering efficiently.
- Platform: Console (Terminal-based)
- Supported OS: Windows & Linux
- Language: C++
👉 Classic Tetris functionality with different shapes
👉 Real-time piece rotation and movement
👉 Score tracking and level progression
👉 Game pause and resume feature
👉 Terminal-based UI for smooth gameplay
- Clone the Repository:
git clone https://github.com/Tirth9978/Tetris_Game.git- Navigate to the Directory:
cd Tetris_Game- Compile the Code:
g++ tetris.cpp -o tetris- Run the Game:
./tetris- Type:
vector<vector<int>> - Purpose: Stores the game grid where the pieces are placed.
- Usage:
vector<vector<int>> board(height, vector<int>(width, 0));height- Number of rows in the boardwidth- Number of columns in the board
- Type:
vector<vector<int>> - Purpose: Represents the current active Tetris piece.
- Usage:
vector<vector<int>> Piece;- Used during piece placement and rotation.
- Type:
pair<int, int> - Purpose: Tracks the x and y coordinates of the active piece.
- Usage:
int x, y; // Current position of the piece- Type:
queue<vector<vector<int>>> - Purpose: Maintains a queue of upcoming pieces.
- Usage:
queue<vector<vector<int>>> nextPieces;- Type:
map<int, vector<vector<int>>> - Purpose: Stores different rotations of each piece for easy access.
- Usage:
map<int, vector<vector<int>>> rotations;| Variable | Type | Purpose |
|---|---|---|
board |
vector<vector<int>> |
Stores the current game board |
Piece |
vector<vector<int>> |
Represents the active piece |
x, y |
int |
Position of the current piece |
width |
int |
Width of the game board |
height |
int |
Height of the game board |
score |
int |
Tracks the player's score |
maxScore |
int |
Stores the highest score achieved |
isPaused |
bool |
Checks if the game is paused |
nextPieces |
queue<vector<vector<int>>> |
Holds upcoming Tetris pieces |
rotations |
map<int, vector<vector<int>>> |
Stores rotations of pieces |
-
Initialization:
- Initializes the board, piece queue, and other variables.
- Generates the first piece and sets the starting position.
-
Piece Movement:
- Handles left, right, and downward movements.
- Validates boundary conditions to prevent overlap.
-
Rotation:
- Uses
RotateLeft()andRotateRight()to change piece orientation. - Ensures rotated piece fits within the grid.
- Uses
-
Collision Detection:
- Checks for collision with other pieces or grid boundaries.
-
Line Clearance:
- Detects full rows and clears them, updating the score.
-
Game Pause/Resume:
- Toggles game state between paused and active.
vector<vector<int>> RotateLeft(vector<vector<int>> mat) {
int row = mat.size();
int col = mat[0].size();
vector<vector<int>> temp(col, vector<int>(row));
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
temp[col - j - 1][i] = mat[i][j];
}
}
return temp;
}#- Represents a filled cell.- Represents an empty cell<><>- Board boundaries
📦 Tetris_Game
└── 💚 tetris.cpp → Main game logic
└── 💚 README.md → Project documentation
└── 💚 Makefile → Build automation (optional)
- Fork the repo and submit a PR with your changes.
- Ensure the code follows best C++ practices.
- Add comments and document new functionality.
📌 Author: Tirth Patel
📌 GitHub: Tirth9978
🎉 Enjoy playing Tetris and feel free to contribute or suggest improvements!
- 👨💻 Tirth Patel (202401157)
- 👨💻 Raj Patel (202401152)
- 👨💻 Shlok Patel (202401156)
- 👨💻 Prakriti Pandey (202401164)
If you liked this project, give it a ⭐ and share it with your friends!
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.