Home

Awesome

Tetrigo

teh·tree·go

app demo

A Golang implementation of Tetris, following the official 2009 Tetris Design Guideline.

This project consists of three main components, depending on what your goals are:

You can find more information on these sections in the development section. If you have a suggestion, bug, or feature request, please open a GitHub issue.

Contents

Installation

Tetrigo can be installed by downloading the binary or by building from source. See the instructions below for your preferred method.

Binary

You can download the binary corresponding to your operating system from the releases page on GitHub.

Once downloaded you can run the binary from the command line:

# Linux or macOS
./tetrigo

# Windows
tetrigo.exe

Optionally, you can move the binary to a directory in your $PATH to run it from anywhere (example).

Build From Source

Ensure that you have a supported version of Go properly installed and setup. You can find the minimum required version of Go in the go.mod file.

You can then install the latest release globally by running:

go install github.com/Broderick-Westrope/tetrigo/cmd/tetrigo@latest

Or you can install into another directory:

env GOBIN=/bin go install github.com/Broderick-Westrope/tetrigo/cmd/tetrigo@latest

Usage

For general information on how to play Tetris see this beginners guide.

Controls

The default game controls are as follows:

The game controls can be changed in the configuration file.

The menu, leaderboard, etc can be navigated using the arrow keys (moving), escape (exit), and enter (submit). These controls are not configurable.

Configuration

CLI

Starting Tetrigo with no subcommand or flags will start the game in the menu where you can manually configure simple settings like the player name and game mode:

./tetrigo

You're also able to start the game directly in a game mode (eg. Marathon), skipping the menu:

# Start the game in Marathon mode with a level of 5 and the player name "Brodie"
./tetrigo play marathon --level=5 --name=Brodie 

To see more options for starting the game you can run:

./tetrigo --help

TOML

More complex configuration can be done using a TOML file. If no config file is found sensible defaults will be used.

By default, Tetrigo will look for the file config.toml in the working directory. You can specify a different file using the --config flag.

./tetrigo --config=/path/to/config.toml

An example configuration file is provided in example.config.toml.

Data

The game data is stored in a SQLite database. By default, the database is stored in the working directory as tetrigo.db. You can specify a different file using the --db flag.

./tetrigo --db=/path/to/data.db

Development

This project consists of three main components:

  1. cmd/tetrigo/: A TUI (Text User Interface) allowing you to play it out of the box. It also serves as a demonstration on how to use the packages and how to create a TUI using Bubble Tea.
  2. pkg/tetris/modes/: The functionality for different Tetris game modes. This can be used to easily create a Tetris game with your own UI but without needing to know the ruleset.
  3. pkg/tetris/: The core Tetris logic, including things like Tetrminimos, the Matrix, and scoring. This can be used to create game modes with your own ruleset and requirements.

Task is the build tool used in this project. The Task config lives in Taskfile.yaml. Once the Task CLI is installed, you can see all available tasks by running:

task -l

You can run the TUI using the run task:

task run

Building

You can build the project using the build task:

task build

This will create a binary in the bin/ directory which can be run using the instructions in the Installation section.

Testing

Tests can be run using the test task:

task test

You can also use the cover task to generate and open a coverage report:

task cover

The ordered priorities for testing are:

  1. pkg/tetris/
  2. pkg/tetris/modes/
  3. cmd/tetrigo/

TODO