Skip to content

Bendz07/TetrisGame

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🎮 Tetris Game — Java Swing (Eclipse IDE)

A classic Tetris game built with Java and Swing GUI, designed to run in Eclipse IDE.


📁 Project Structure

TetrisGame/
├── src/
│   ├── Tetris.java        # Main entry point — launches the game window
│   ├── TetrisGame.java    # Game panel — rendering, input handling, game loop
│   ├── Board.java         # Board logic — grid, line clearing, piece placement
│   └── Tetromino.java     # Piece logic — shapes, colors, movement, rotation
└── README.md

🚀 Getting Started

Prerequisites

  • Java JDK 8 or higher
  • Eclipse IDE (any recent version)

Setup in Eclipse

  1. Open Eclipse → File → New → Java Project
  2. Name the project TetrisGame and click Finish
  3. Right-click the src folder → New → Class for each of the four files:
    • Tetris
    • TetrisGame
    • Board
    • Tetromino
  4. Paste the corresponding source code into each class file
  5. Right-click Tetris.javaRun As → Java Application

🕹️ Controls

Key Action
Move left/right
Rotate piece
Soft drop
Space Hard drop
P Pause / Resume

🎯 Gameplay

  • Pieces fall from the top of the board one at a time
  • Complete horizontal lines to clear them and earn points
  • The game ends when a new piece cannot spawn (board is full)
  • Score increases based on how many lines are cleared at once:
Lines Cleared Points
1 100
2 400
3 900
4 1600

🟦 Tetromino Pieces

Piece Shape Color
I ████ Cyan
O ██ Yellow
██
T ███ Magenta
L ███ Orange
J ███ Blue
S ██ Green
Z ██ Red

🗂️ File Descriptions

Tetris.java

The entry point of the application. Creates the JFrame window, adds the game panel, sets window properties, and starts the game loop.

TetrisGame.java

Extends JPanel and implements ActionListener. Responsible for:

  • Rendering the board and active piece using paintComponent
  • Handling keyboard input (movement, rotation, drop, pause)
  • Running the game timer that drives piece descent
  • Tracking and displaying the score

Board.java

Manages the game grid (a 2D integer array). Handles:

  • Collision/validity checking for piece placement
  • Locking a piece onto the board when it lands
  • Detecting and clearing completed lines
  • Storing color indices for rendering

Tetromino.java

Represents a single falling piece. Handles:

  • All 7 standard piece shapes (I, O, T, L, J, S, Z)
  • Random piece generation
  • Movement (translate x/y)
  • Clockwise and counter-clockwise rotation

🛠️ Customization

You can easily tweak the following constants in TetrisGame.java:

private static final int BOARD_WIDTH = 10;   // Number of columns
private static final int BOARD_HEIGHT = 20;  // Number of rows
private static final int CELL_SIZE = 30;     // Pixel size of each cell

And adjust the game speed (in milliseconds) by changing the timer delay:

timer = new Timer(500, this); // Lower = faster

📸 Screenshot

┌──────────────────────────────┬─────────────────┐
│                              │  Score: 400      │
│         [ Tetris Board ]     │                  │
│                              │  Controls:       │
│                              │  ← →  Move       │
│                              │  ↑    Rotate     │
│                              │  ↓    Soft Drop  │
│                              │  Space Hard Drop │
│                              │  P    Pause      │
└──────────────────────────────┴─────────────────┘

📄 License

This project is open source and free to use for educational purposes.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages