Skip to content

itssimmons/tetris.cpp

Command-Line Tetris made with C++

WhatsApp Video 2026-02-21 at 18 29 07

This is a simple implementation of the classic Tetris game using C++. The game is played in the terminal, and it features very basic Tetris mechanics such as rotating and moving pieces, clearing lines.

Table of Contents

Download and Play

Visit the project’s Releases page and download the binary that corresponds to your operating system. Once downloaded, execute the file from your terminal to begin the game.

Warning

⚠️ Terminal Compatibility: Ensure that your terminal emulator supports ANSI escape sequences; otherwise, colors and screen rendering may not display correctly.

Important

🔒 Security Notice: Precompiled binaries may be flagged by your operating system’s security mechanisms because they are unsigned.

  • Windows: If a SmartScreen warning appears, select “More info” and then “Run anyway.”

  • MacOS: You may need to remove the quarantine attribute:

    xattr -d com.apple.quarantine /path/to/tetris
  • Linux: Grant execute permission before running:

    chmod +x /path/to/tetris

Requirements to Code

  • A C++ compiler (like g++)
  • Terminal or command-line interface (ANSI support for better visuals)
  • Bazel build system (optional, but recommended for building the project)
  • C++20 or later

Building the Project

  1. Clone the repository:
git clone https://github.com/itssimmons/tetris.cpp.git
cd tetris.cpp
  1. Build the project using Bazel:
bazel build //tetris:tetris

Running the Game

After building the project, you can run the game using the following command:

bazel run //tetris:tetris

Controls

  • : Move piece left
  • : Move piece right
  • : Soft drop piece
  • : Rotate piece (clockwise)
  • space: Drop piece instantly
  • esc: Exit the game
  • Z: Rotate piece (counter-clockwise)
  • X: Rotate piece (clockwise)

Features

  • Basic Tetris mechanics (moving, rotating, and dropping pieces).
  • Line clearing.
  • Game over condition when pieces stack up to the top of the playfield.
  • The size of the board is based on the size of the terminal window, allowing for a dynamic play area.
  • Frame rate of 30 FPS for smooth gameplay in a terminal environment.
  • Piece generation using "seed" based randomization for reproducibility.
  • ANSI escape codes for better visuals in the terminal.

Future Improvements

  • Implementing a scoring system.
  • Accelerating piece speed as the game progresses.
  • Implementing a hold piece feature.
  • Implementing a next pieces preview.
  • Adding sound effects (if possible in a terminal environment).
  • Spinning mechanics and T-spin recognition.
  • CLI options for customizing the game (e.g., board size, piece colors, base speed, etc...).

License

This project is licensed under the MIT License - see the LICENSE file for details

Contributing

Contributions are welcome! If you have any ideas for improvements or want to fix bugs, feel free to submit a pull request or open an issue.

About

Command-Line Tetris made with C++

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Contributors 2

  •  
  •