https://github.com/datslim/tetris-c
A classic Tetris implementation in C designed to run in the terminal.
https://github.com/datslim/tetris-c
c cli game terminal tetris
Last synced: 4 months ago
JSON representation
A classic Tetris implementation in C designed to run in the terminal.
- Host: GitHub
- URL: https://github.com/datslim/tetris-c
- Owner: datslim
- License: mit
- Created: 2025-03-31T16:02:03.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-31T17:29:03.000Z (over 1 year ago)
- Last Synced: 2025-08-24T23:32:52.529Z (10 months ago)
- Topics: c, cli, game, terminal, tetris
- Language: C
- Homepage:
- Size: 77.1 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Tetris in C
[](https://opensource.org/licenses/MIT)
[](https://libcheck.github.io/check/)
[](https://gcc.gnu.org/onlinedocs/gcc/Gcov.html)
[](https://www.doxygen.nl/)
A classic Tetris implementation in **C** with code coverage analysis, unit tests, and full documentation.

## Table of Contents
- [โจ Features](#-features)
- [๐ ๏ธ Installation](#๏ธ-installation)
- [๐งฐ Dependencies](#-dependencies)
- [๐ง๐ Linux/macOS](#-linuxmacos)
- [๐๏ธ Project Structure](#๏ธ-project-structure)
- [๐งช Testing](#-testing)
- [๐ Code Coverage](#-code-coverage)
- [๐ Documentation](#-documentation)
- [๐น๏ธ Keyboard Controls](#๏ธ-keyboard-controls)
- [๐ Development Workflow](#-development-workflow)
- [๐ค Contributing](#-contributing)
- [๐ License](#-license)
## โจ Features
- ๐ฎ **Classic Tetris mechanics** (rotation, movement, hard drop)
- ๐ **Score & level system** (higher score = higher level)
- โฑ **Dynamic difficulty** (speed increases with levels)
- ๐งช **Unit tests** (powered by [Check](https://libcheck.github.io/check/))
- ๐ **Code coverage** (generated with [gcov/lcov](https://gcc.gnu.org/onlinedocs/gcc/Gcov.html))
- ๐ **Documentation** (generated with [Doxygen](https://www.doxygen.nl/))
## ๐ ๏ธ Installation
```bash
# Install the game
make install
```
### ๐งฐ Dependencies
- C compiler (GCC)
- NCurses
- *Optional*:
- `check` (for unit tests)
- `doxygen` (for documentation)
- `graphviz` (for Doxygen diagrams)
- `gcov\lcov` (for code coverage)
### ๐ง๐ Linux/macOS
```bash
# Install dependencies (Debian/Ubuntu)
sudo apt-get install libncurses5-dev libncursesw5-dev check graphviz lcov gcovr
```
```bash
# Compile & run
make
```
## ๐๏ธ Project Structure
```
tetris-c/
โโโ brick_game/ # Source files for backend
โโโ tests/ # Unit tests
โโโ gcov/ # Test coverage data (autogenerated via Makefile)
โโโ doxygen/ # Files for generating documentation
โโโ doxygen_files/ # Generated documentation (autogenerated via Makefile)
โโโ build/ # Folder for compiled game and tests files (autogenerated via Makefile)
โโโ gui/ # Source files for frontend
โโโ unit_tests/ # Unit-tests for backend
โโโ main.c # Entry point for the game
โโโ Makefile # Build configuration
```
## ๐งช Testing
Project includes unit tests using the Check framework:
```bash
# Build and run tests
make test
```
## ๐ Code coverage
Project includes code coverage test using the GCOV\LCOV:
```bash
# Generate and open coverage report
make gcov_report
```
## ๐ Documentation
Generate HTML/LaTeX docs via Doxygen:
```bash
# Generate and open documentation
make dvi
```
## ๐น๏ธ Keyboard Controls
- ***โ โ***: Move left\right
- **โ**: Instant drop (hard drop)
- **โต**: Rotate piece
- **P**: Pause game
- **Q**: Quit to menu
- **R**: Restart game
## ๐ Development Workflow
1. Write code in ```brick_game/```
2. Add tests in ```unit_tests/```
3. Check coverage
```bash
make gcov_report
```
4. Ensure coverage doesn't drop below 80%
## ๐ค Contributing
1. Fork the repository
2. Create your feature branch (```git checkout -b feature/fooBar```)
3. Commit your changes (```git commit -am 'Add some fooBar'```)
4. Push to the branch (```git push origin feature/fooBar```)
5. Create a new Pull Request
## ๐ License
Distributed under the MIT License. See [LICENSE](LICENSE) for more information.
๐ฏ Enjoy the game! If you find this project useful, please consider giving it a โญ!