A modern, professionally-architected implementation of the classic Pong game using State Pattern, MVC Architecture, and best practices in game development.
- ๐ฎ Two-Player Local Multiplayer - Classic head-to-head gameplay
- ๐จ Professional Architecture - State Pattern + MVC for clean, maintainable code
- ๐๏ธ Design Patterns - Singleton, State, Observer, and more
- ๐ Comprehensive Documentation - Fully documented with docstrings and type hints
- โ Unit Tested - Tested components ensure reliability
- ๐ง Modular Design - Easy to extend with new features
- ๐ฏ Separation of Concerns - Models, Views, and Controllers clearly separated
The project follows professional software engineering practices with a clean MVC architecture and multiple design patterns:
- State Pattern - Game states (Menu, Playing, Paused, GameOver)
- MVC Pattern - Separation of Models, Views, and Controllers
- Singleton Pattern - GameManager as single game instance
- Observer Pattern - Event-based communication (planned)
- Strategy Pattern - Pluggable input controllers
game/
โโโ __init__.py
โโโ game_manager.py # Singleton GameManager + main loop
โโโ game_states.py # State Pattern implementation
โ
โโโ models/ # Business Logic Layer
โ โโโ __init__.py
โ โโโ entities.py # Ball, Paddle (game entities)
โ โโโ game_model.py # PongGameModel (game state)
โ
โโโ views/ # Presentation Layer
โ โโโ __init__.py
โ โโโ game_view.py # Game rendering
โ โโโ menu_view.py # Menu screen
โ โโโ pause_view.py # Pause overlay
โ
โโโ controllers/ # Control Layer
โโโ __init__.py
โโโ input_controller.py # Input handling
โโโ collision_controller.py # Collision logic
app.py (Entry Point)
โ
โโโ GameManager (Singleton)
โ โโโ StateManager
โ โ โโโ MenuState
โ โ โโโ PlayingState
โ โ โโโ PausedState
โ โ โโโ GameOverState
โ โ
โ โโโ PlayingState (Active)
โ โโโ PongGameModel (Model)
โ โ โโโ Ball
โ โ โโโ Paddle (x2)
โ โ
โ โโโ GameView (View)
โ โ
โ โโโ Controllers
โ โโโ InputController
โ โโโ CollisionController
| Player | Up | Down |
|---|---|---|
| Player 1 (Left) | W | S |
| Player 2 (Right) | โ Arrow | โ Arrow |
Other Controls:
ESC- Pause game / Back to menuEnter/Space- Select menu option
- Python 3.8 or higher
- Pygame 2.5.2
- Colorama 0.4.6
# Clone the repository
git clone https://github.com/userlg/Pong-Python.git
cd Pong-Python
# Create virtual environment
python -m venv .venv
# Activate virtual environment
# On Windows:
.venv\Scripts\activate
# On macOS/Linux:
# source .venv/bin/activate
# Install dependencies
pip install -r requirements.txt
# Run the game
python app.py# Clone the repository
git clone https://github.com/userlg/Pong-Python.git
cd Pong-Python
# Install dependencies
pip install -r requirements.txt
# Run the game
python app.py# Build the image
docker build -t pong-python .
# Run the container
docker run -it pong-python- First player to reach 5 points wins
- Ball speed adjusts based on paddle hit position
- Game enters Game Over state when winner is determined
- Press Space/Enter to play again or ESC for menu
Run the test suite:
# Install development dependencies
pip install -r requirements-dev.txt
# Run tests
pytest tests/ -v
# Run tests with coverage
pytest tests/ --cov=. --cov-report=htmlThis project uses several tools to maintain code quality:
- Black - Code formatting
- Flake8 - Linting
- MyPy - Type checking
- isort - Import sorting
# Install development dependencies
pip install -r requirements-dev.txt
# Format code
black .
# Run linter
flake8 .
# Type check
mypy .
# Sort imports
isort .Set up pre-commit hooks to automatically check code quality:
# Install pre-commit
pip install pre-commit
# Install git hooks
pre-commit install
# Run manually on all files
pre-commit run --all-filesContributions are welcome! This project now uses professional design patterns making it easier to add new features:
Easy additions thanks to architecture:
- New game states (Settings, Tutorial, etc.)
- Different game modes
- AI opponents
- Custom themes
- Power-ups and special effects
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Follow the existing architecture patterns
- Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Userlg - GitHub Profile
- Classic Pong game by Atari
- Pygame community for excellent documentation
- Design patterns community for architecture guidance
- All contributors who help improve this project
- Add AI opponent for single-player mode
- Implement difficulty levels
- Add sound effects and background music
- Create power-ups and special effects
- Add online multiplayer support
- Implement leaderboard system
- Add customizable themes and colors
- Create settings menu with controls remapping
State Pattern Benefits:
- Easy to add new game states
- Clear state transitions
- Each state manages its own logic
- Reduced complexity in main loop
MVC Benefits:
- Separation of concerns
- Easier testing
- Reusable components
- Clear data flow
Testability:
- Models can be tested independently
- Views can be mocked
- Controllers have clear interfaces
- Maintains consistent 60 FPS
- Efficient rendering with cached resources
- Clean resource management
- No memory leaks in state transitions
Made with โค๏ธ and professional design patterns by Userlg
Version 2.0.0 - Professional Architecture Edition


