This is a Tetris game implemented in Python using the Pygame library.

- Classic Tetris gameplay
- Seven standard Tetromino shapes
- Next block preview
- Ghost piece preview for easier placement
- Score, level, and lines cleared display
- Increasing difficulty (speed) with levels
- Smooth animations
- Sound effects and background music with mute option (press 'M' to toggle)
- Start menu with top scores display
- Player name input at game start (defaults to "Anonymous" if empty)
- Pause functionality (press 'P' or 'S' to toggle)
- Game over screen with top scores display
- Scrolling top 10 players leaderboard (continuous animation until any key is pressed)
- Simultaneous line clearing animation for multiple rows
- Multiple game states (menu, playing, paused, game over)
- SQLite database for storing and retrieving game scores
- Performance grading system (S, A, B, C, D, F)
- High score leaderboard
- Python 3.6+
- pygame >=2.6.1
- SQLite3 (included in Python standard library)
- Make sure you have Python 3.x installed on your system.
- Clone this repository or download the source code.
- Navigate to the project directory in your terminal.
- Install the required dependencies using pip:
pip install -r requirements.txt
- Navigate to the project directory in your terminal.
- Run the following command:
python tetris.py
- Left Arrow: Move block left
- Right Arrow: Move block right
- Down Arrow: Soft drop
- Up Arrow: Rotate block clockwise
- Spacebar: Hard drop
- P or S: Pause/Resume game
- M: Toggle mute for all sounds and music
- R: Restart game (when game over)
- Q: Quit to main menu (during gameplay or game over)
- S: Pause/Resume game (during gameplay) or view scrolling top 10 players (when game over)
- N: Enter name to save score (when game over)
- H: View high scores (when game over)
- B: Go back from high scores screen
- Any key: Return from scrolling scores screen
- The game speed increases with each level
- Every 10 lines cleared increases the level
- Scoring system:
- 1 line: 40 points × level
- 2 lines: 100 points × level
- 3 lines: 300 points × level
- 4 lines: 1200 points × level
- Grading system:
- S: 10,000+ points
- A: 7,500-9,999 points
- B: 5,000-7,499 points
- C: 2,500-4,999 points
- D: 1,000-2,499 points
- F: 0-999 points
tetris.py
: Main game file with game loop and state managementrequirements.txt
: List of project dependenciestetris_scores.db
: SQLite database file (created on first run)game/
__init__.py
game.py
: Game class (main game logic)sound.py
: Sound class (handles sound effects and music)database.py
: Database class (handles score storage and retrieval)components/
block.py
: Block class (Tetromino implementation)board.py
: Board class (game board and collision detection)
GamesAI/
│
├── assets/
│ ├── background.mp3
│ ├── clear.mp3
│ ├── drop.mp3
│ ├── gameover.mp3
│ ├── rotate.mp3
│ └── Game demo.gif
│
├── game/
│ ├── components/
│ │ ├── __init__.py
│ │ ├── block.py
│ │ └── board.py
│ │
│ ├── __init__.py
│ ├── database.py
│ ├── game.py
│ └── sound.py
│
├── .env
├── .gitignore
├── README.md
├── requirements.txt
├── splunk_mcp.log
├── tetris_scores.db
└── tetris.py
Make sure to place your sound files in an assets
folder:
assets/rotate.mp3
assets/clear.mp3
assets/drop.mp3
assets/gameover.mp3
assets/background.mp3
You can easily customize various aspects of the game by modifying the constants in the respective files:
- Block colors and shapes:
game/components/block.py
- Board size:
game/components/board.py
- Game speed and scoring:
game/game.py
- Menu: The initial state where players can start a new game or quit
- Start Name Input: Allows the player to enter their name before starting the game
- Playing: The main gameplay state
- Paused: When the game is paused (music stops, overlay displayed)
- Game Over: Displays the final score, top scores, and allows restarting or quitting
- High Scores: Displays the top scores from the database
- Name Input: Allows the player to enter their name before saving their score
- Scrolling Scores: Displays top 10 players scrolling from bottom to top continuously until any key is pressed
- Added visually appealing gradient background to the menu
- Created animated Tetris-themed border around the title
- Implemented interactive button-like elements with hover effects
- Added mouse support for menu navigation
- Improved high scores display with proper table formatting
- Added visual indicators for top-ranked players
- Fixed menu layout to prevent text and UI element overlapping
- Optimized spacing between menu elements for better readability
- Added mute functionality (press 'M' to toggle all sounds and music)
- Mute status is displayed on all game screens
- Mute state persists between game states and when restarting
- Added scrolling animation for top 10 players display
- Scores continuously scroll from bottom to top until any key is pressed
- Fixed UI elements positioning to ensure all text is fully visible
- Added shadow effects for better text readability
- Fixed bug where multiple completed rows wouldn't disappear simultaneously
- Improved line clearing animation to handle multiple rows at once
- Enhanced player name input with clearer instructions
- Added alternative pause/resume control with 'S' key
- Added game status display showing current pause/resume state
Enjoy playing Tetris!