An open API service indexing awesome lists of open source software.

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.

Awesome Lists containing this project

README

          

# Tetris in C

[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![Testing](https://img.shields.io/badge/Testing-Check-green)](https://libcheck.github.io/check/)
[![Coverage](https://img.shields.io/badge/Coverage-gcov/lcov-blue)](https://gcc.gnu.org/onlinedocs/gcc/Gcov.html)
[![Docs](https://img.shields.io/badge/Docs-Doxygen-blueviolet)](https://www.doxygen.nl/)

A classic Tetris implementation in **C** with code coverage analysis, unit tests, and full documentation.

![Gameplay Screenshot](doxygen/images/game_screenshot.png)
## 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 โญ!