Skip to content

๐ŸŽฎ A C++20 Tetris game running in the Linux terminal.

License

Notifications You must be signed in to change notification settings

Zhuagenborn/Tetris

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

23 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Tetris

C++ CMake Docker GitHub Actions Linux License

Introduction

Cover

A Tetris game running in the Linux terminal.

Prerequisites

Building

Set the location to the project folder and run:

mkdir build
cd build
cmake ..
cmake --build .

Running Tests

Set the location to the build folder and run:

ctest -VV

Running the Game

Set the location to the build/bin folder and run:

./tetris -x=<width> -y=<height>

For example:

./tetris -x=10 -y=15

Structure

.
โ”œโ”€โ”€ .clang-format
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ CITATION.cff
โ”œโ”€โ”€ CMakeLists.txt
โ”œโ”€โ”€ Dockerfile
โ”œโ”€โ”€ LICENSE
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ cover.png
โ”œโ”€โ”€ docs
โ”‚   โ””โ”€โ”€ badges
โ”‚       โ”œโ”€โ”€ C++.svg
โ”‚       โ”œโ”€โ”€ License-MIT.svg
โ”‚       โ”œโ”€โ”€ Linux.svg
โ”‚       โ”œโ”€โ”€ Made-with-CMake.svg
โ”‚       โ”œโ”€โ”€ Made-with-GitHub-Actions.svg
โ”‚       โ””โ”€โ”€ Made-with-Docker.svg
โ”œโ”€โ”€ include
โ”‚   โ”œโ”€โ”€ args.h
โ”‚   โ”œโ”€โ”€ color.h
โ”‚   โ”œโ”€โ”€ controller.h
โ”‚   โ”œโ”€โ”€ game.h
โ”‚   โ”œโ”€โ”€ grid.h
โ”‚   โ”œโ”€โ”€ location.h
โ”‚   โ”œโ”€โ”€ rotation.h
โ”‚   โ”œโ”€โ”€ shape.h
โ”‚   โ””โ”€โ”€ tetromino.h
โ”œโ”€โ”€ src
โ”‚   โ”œโ”€โ”€ CMakeLists.txt
โ”‚   โ”œโ”€โ”€ args
โ”‚   โ”‚   โ”œโ”€โ”€ CMakeLists.txt
โ”‚   โ”‚   โ””โ”€โ”€ args.cpp
โ”‚   โ”œโ”€โ”€ color
โ”‚   โ”‚   โ”œโ”€โ”€ CMakeLists.txt
โ”‚   โ”‚   โ””โ”€โ”€ color.cpp
โ”‚   โ”œโ”€โ”€ controller
โ”‚   โ”‚   โ”œโ”€โ”€ CMakeLists.txt
โ”‚   โ”‚   โ”œโ”€โ”€ controller.cpp
โ”‚   โ”‚   โ””โ”€โ”€ ui
โ”‚   โ”‚       โ”œโ”€โ”€ board.h
โ”‚   โ”‚       โ”œโ”€โ”€ color_env.cpp
โ”‚   โ”‚       โ”œโ”€โ”€ color_env.h
โ”‚   โ”‚       โ”œโ”€โ”€ grid_board.h
โ”‚   โ”‚       โ”œโ”€โ”€ next_tetromino_board.h
โ”‚   โ”‚       โ””โ”€โ”€ score_board.h
โ”‚   โ”œโ”€โ”€ game
โ”‚   โ”‚   โ”œโ”€โ”€ CMakeLists.txt
โ”‚   โ”‚   โ””โ”€โ”€ game.cpp
โ”‚   โ”œโ”€โ”€ grid
โ”‚   โ”‚   โ”œโ”€โ”€ CMakeLists.txt
โ”‚   โ”‚   โ””โ”€โ”€ grid.cpp
โ”‚   โ”œโ”€โ”€ location
โ”‚   โ”‚   โ””โ”€โ”€ CMakeLists.txt
โ”‚   โ”œโ”€โ”€ main.cpp
โ”‚   โ”œโ”€โ”€ rotation
โ”‚   โ”‚   โ”œโ”€โ”€ CMakeLists.txt
โ”‚   โ”‚   โ””โ”€โ”€ rotation.cpp
โ”‚   โ”œโ”€โ”€ shape
โ”‚   โ”‚   โ””โ”€โ”€ CMakeLists.txt
โ”‚   โ””โ”€โ”€ tetromino
โ”‚       โ”œโ”€โ”€ CMakeLists.txt
โ”‚       โ”œโ”€โ”€ subtype
โ”‚       โ”‚   โ”œโ”€โ”€ i.h
โ”‚       โ”‚   โ”œโ”€โ”€ j.h
โ”‚       โ”‚   โ”œโ”€โ”€ l.h
โ”‚       โ”‚   โ”œโ”€โ”€ o.h
โ”‚       โ”‚   โ”œโ”€โ”€ s.h
โ”‚       โ”‚   โ”œโ”€โ”€ t.h
โ”‚       โ”‚   โ””โ”€โ”€ z.h
โ”‚       โ””โ”€โ”€ tetromino.cpp
โ””โ”€โ”€ tests
    โ”œโ”€โ”€ CMakeLists.txt
    โ”œโ”€โ”€ grid_test.cpp
    โ”œโ”€โ”€ rotation_test.cpp
    โ””โ”€โ”€ tetromino_test.cpp

Class Diagram

classDiagram

class Colored {
    <<interface>>
    GetColor() Color
    SetColor(Color)
}

class Rotatable {
    <<interface>>
    RotateLeft()
    RotateRight()
    GetAngle() Angle
    RotateTo(Angle)
}

class Locatable {
    <<interface>>
    GetPosition() Point
}

class Movable {
    <<interface>>
    SetPosition(Point)
}

Locatable <|-- Movable

class Shape {
    <<interface>>
    GetHeight() int
    GetWidth() int
    Filled(Point) bool
}

class Tetromino {
    <<abstract>>
    GetTetrominoByAngle(Angle) Tetromino
}

Shape <|.. Tetromino
Rotatable <|.. Tetromino
Colored <|.. Tetromino

Tetromino <|-- I
Tetromino <|-- O
Tetromino <|-- J
Tetromino <|-- L
Tetromino <|-- S
Tetromino <|-- T
Tetromino <|-- Z

class Grid {
    GetColor(Point) Color
    PushTetromino(Tetromino, Point) bool
    MoveTetrominoToLeft() bool
    MoveTetrominoToRight() bool
    RotateTetrominoLeft() bool
    RotateTetrominoRight() bool
    TetrominoDescend(int& cleared_line_count) bool
}

Shape <|.. Grid
Grid *-- Tetromino

Movable <|.. MovableTetromino
MovableTetromino --> Tetromino
Grid --> MovableTetromino

class Action {
    <<enumeration>>
    Non
    MoveToLeft
    MoveToRight
    RotateLeft
    RotateRight
    Descend
}

class Game {
    Start()
    Act(Action) ActionResult
    GetNextTetrominoes() Tetromino
    GetScore() int
    IsOver() bool
}

Game --> Grid
Game ..> Action

class Controller {
    Input()
    Update()
    Refresh()
}

Controller --> Game

License

Distributed under the MIT License. See LICENSE for more information.