A Java Swing implementation of Tetris built for the Programação Orientada a Objetos (POO) course at LEI (IPT). The project demonstrates OOP fundamentals - inheritance, polymorphism, cloning, and encapsulation - applied to classic Tetris mechanics.
The board is rendered as monospace text inside a JTextArea, with all game logic (piece movement, rotation, collision, freezing, line generation) implemented from scratch, without any external game library.
The repo contains two NetBeans/Ant projects:
| Project | Description |
|---|---|
TetrisFinal |
The complete game: full Swing GUI (main menu, about, rules, options screens), configurable board size, all 7 tetromino types. This is the project to run. |
SuperTetris |
An earlier prototype of the core Block / BlockMatrix / Piece classes, kept alongside unit tests used to validate the model before the final GUI was built. |
- All 7 standard tetrominoes (I, J, L, O, S, T, Z)
- Piece movement (left/right/down), rotation with basic wall-kick handling, and hard drop
- Configurable board dimensions (rows/columns) via spinner controls
- Main menu with About and Rules screens
- Random piece generation and game-over detection
Core game model (TetrisFinal/src/classes):
Block- a single cell, identified by acharid (.for empty); supports copy-construction and cloning.Empty- aBlocksubclass representing an empty cell.BlockMatrix- a 2D grid ofBlocks with clone and in-placerotate()(matrix transpose + reverse) support.Piece(classes.pieces) - extendsBlockMatrix, adds an(x, y)board position and movement methods. Each tetromino (PieceI,PieceJ,PieceL,PieceO,PieceS,PieceT,PieceZ) is aPiecesubclass that hardcodes its own shape.Board- extendsBlockMatrix, owns the currently fallingPiece, and implements collision detection, movement validation, rotation with wall-kicks, freezing a piece into the board, and loss detection.
GUI (TetrisFinal/src/gui, NetBeans .form-backed): MainMenu, Tetris (game screen), About, Rules, Options.
- JDK 19+
- Apache Ant (or open directly in Apache NetBeans, which the project was authored in)
cd TetrisFinal
ant runOr open TetrisFinal as a project in NetBeans and run it directly.
Movement is button-driven from the game screen: ◄ / ▼ / ► to move, ↻ to rotate, FALL to hard-drop the current piece.
Group project for LEI/POO, by Bruno Freitas (@viribusegovis) and Vasco Alves (@vascobrissos).