- Classic 2048 game rules
- Keyboard arrow key controls (↑↓←→)
- Real-time score tracking with best score persistence
- Game win/loss detection
- New game reset functionality
- Beautiful interface design and color schemes
- Smooth animation system:
- Smooth tile movement
- Multi-stage scaling animations on merge
- Golden highlight and flash effects
- New tile elastic appearance animation
- Responsive design and shadow effects
- Object-oriented architecture design
- Complete animation framework with smooth tile merge effects
- Centralized import management via common.py
- Modular code structure with reusable UI components
- Comprehensive error handling
- Python 3.12+
- PySide6
- Clone or download the project
- Install dependencies:
# Install runtime dependencies only (for deployment)
pip install -r requirements.txt
# Or install development dependencies (includes testing tools)
pip install -r requirements-dev.txt
# Or install PySide6 directly
pip install PySide6>=6.0.0# Run in PyCharm
python src/main.py
# Or run in command line
python src/main.py# Install as development package
pip install -e .
# Run
python -m src.main# Automated packaging (recommended)
python package_game.py
# Or use PyInstaller directly
pyinstaller 2048Game.spec
# Simple packaging
pyinstaller --name="2048Game" --windowed --onefile src/main.pyAfter packaging is complete, the executable file is located at:
dist/2048Game.exe- Standalone executable file
- Arrow keys (↑ ↓ ← →): Move tiles
- New Game button: Start a new game
- Goal: Reach 2048 by merging identical numbers
2048-game/
├── 📂 src/ # Source code directory
│ ├── __init__.py # Package initialization
│ ├── main.py # Main program entry
│ ├── main_window.py # Main window and UI components
│ ├── game2048.py # Game logic core
│ ├── common.py # Common imports
│ ├── tile_widget.py # Tile UI component
│ └── game_board_widget.py # Game board widget
├── 📂 tests/ # Test files
│ ├── __init__.py
│ └── test_game.py # Unit tests
├── 🔧 package_game.py # Automated packaging script
├── 🔧 2048Game.spec # PyInstaller configuration
├── 🧪 run_tests.py # Test suite
├── 📄 setup.py # Installation configuration
├── 📄 pyproject.toml # Project configuration
├── 📄 requirements.txt # Runtime dependencies
├── 📄 requirements-dev.txt # Development dependencies
└── 📖 README.md # Project documentation
# Clone the project
git clone <repository-url>
cd 2048-game
# Install development dependencies
pip install -r requirements-dev.txt
# Or install manually
pip install PySide6>=6.0.0 pytest black mypy flake8 isort# Code formatting
black src/ --line-length 88
# Import sorting
isort src/
# Type checking
mypy src/ --python-version 3.12
# Code style checking
flake8 src/
# Run tests
pytest tests/ -v
# Complete test suite
python run_tests.pyThe project includes a complete testing system:
# Run all tests
python run_tests.py
# Unit tests only
pytest tests/ -v
# Run specific test file
pytest tests/test_game.py -v
# Run specific test function
pytest tests/test_game.py::TestGame2048::test_initial_score -v- ✅ Black - Code formatting
- ✅ MyPy - Static type checking
- ✅ Flake8 - Code style checking
- ✅ iSort - Import statement sorting
- ✅ Unit Tests - Component testing with pytest
- Move: Use arrow keys (↑↓←→) to move all tiles
- Merge: Tiles with identical numbers merge into their sum when colliding
- New tile: A new 2 or 4 appears randomly after each move
- Win: Game is won when a 2048 tile appears
- Loss: Game is over when the board is full and no moves are possible
- Keep large numbers in corners when possible
- Avoid separating large numbers with small ones
- Build increasing number sequences
- Maintain consistent movement patterns
| Component | Function | Features |
|---|---|---|
| Game2048 | Game logic core | Move algorithm, merge detection, state management |
| MainWindow | Main window controller | Event handling, UI layout, game flow |
| TileWidget | Number tile component | Animation system, style management, interaction feedback |
| GameBoardWidget | Game board management | Grid layout, animation coordination, state synchronization |
- 🎬 Position Animation:
QPropertyAnimationfor smooth movement - 🎭 Scaling Animation:
QSequentialAnimationGroupfor multi-stage effects - 🌈 Color Transition: Dynamic style changes enhance visual feedback
- ⚡ Performance Optimization: Smart animation queue prevents overlap and lag
- MVC Architecture: Clear separation of Model-View-Controller
- Component-based Design: Reusable UI components
- Event-driven: Responsive user interactions
- State Management: Centralized game state control
The project supports multiple distribution methods:
# Automated packaging (recommended)
python package_game.pyPackaging features:
- ✅ Single file executable (~15-20MB)
- ✅ No Python environment required
- ✅ Cross-Windows version compatible
- ✅ Includes complete dependency libraries
After packaging is complete:
📁 dist/
└── 📄 2048Game.exe # Main executable file
Welcome contributions and improvement suggestions!
- 🐛 Report Issues: Submit an Issue describing a bug
- 💡 Feature Suggestions: Propose new feature ideas
- 🔧 Code Contributions: Submit a Pull Request
- 📖 Documentation Improvements: Improve documentation and instructions
- Fork the project repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit changes (
git commit -m 'Add amazing feature') - Push branch (
git push origin feature/amazing-feature) - Create a Pull Request
- Follow PEP 8 code style
- Use Black for code formatting
- Add appropriate type annotations
- Write unit tests
- Update related documentation
This project is licensed under the MIT License - see the LICENSE file for details
- ✅ Commercial use
- ✅ Modification and distribution
- ✅ Private use
⚠️ Must include license and copyright notice⚠️ No liability warranty provided
Thanks to all developers and users who have contributed to this project!
Tech Stack:
- PySide6 - Qt for Python GUI Framework
- Python - Programming Language
- PyInstaller - Packaging Tool
Inspiration Sources:
- 2048 Original Game by Gabriele Cirulli
- PySide6 official documentation and community
🎮 Enjoy the game, enjoy coding!
Made with ❤️ by [Your Name]
