A modern implementation of the classic Minesweeper game built with Python and Kivy framework, following SOLID design principles for clean, maintainable code.
This Minesweeper implementation features a clean, modern interface with emoji support and follows object-oriented design patterns. The game provides an engaging experience with smooth gameplay, visual feedback, and customizable difficulty levels.
- Smart Mine Generation: Mines are placed after the first click to ensure a fair start
- Intelligent Cell Revealing: Automatically reveals adjacent empty cells
- Flag System: Right-click to mark suspected mines
- Win/Loss Detection: Clear victory and defeat conditions
- Game Reset: Quick restart functionality
- Emoji Support: Modern emoji-based mine and flag indicators (๐ฃ๐ฉ)
- Color-Coded Numbers: Each number has a distinct color for easy recognition
- Clean UI: Minimalist design with clear cell states
- Alternative Themes: Switch between emoji and text-based renderers
- Responsive Layout: Adapts to different window sizes
- SOLID Architecture: Clean separation of concerns with MVC pattern
- Observer Pattern: Real-time UI updates based on game state changes
- Strategy Pattern: Pluggable cell rendering systems
- Interface-Based Design: Easy to extend and modify
- Type Hints: Full type annotation for better code maintainability
The project follows SOLID principles with a clear separation of concerns:
โโโ models/ # Game logic and state management
โโโ views/ # UI components and rendering
โโโ controllers/ # Input handling and coordination
โโโ interfaces/ # Abstract interfaces and contracts
โโโ utils/ # Utility classes and helpers
- MinesweeperModel: Core game logic, mine placement, and state management
- MinesweeperView: Kivy-based UI with customizable cell rendering
- MinesweeperController: Coordinates between model and view, handles user input
- Cell Renderers: Pluggable rendering strategies (Default/Minimalist themes)
- Python 3.7 or higher
- Kivy framework
-
Clone the repository:
git clone <repository-url> cd minesweeper-kivy
-
Install dependencies:
pip install kivy
-
Run the game:
python main.py
- Left Click: Reveal a cell
- Right Click: Toggle flag on a cell
- Reset Button: Start a new game
Clear all cells that don't contain mines. Numbers indicate how many mines are adjacent to that cell.
- Click on cells to reveal them
- Numbers show adjacent mine count
- Use flags to mark suspected mines
- Avoid clicking on mines
- Win by revealing all safe cells
- Grid Size: 15ร15 cells
- Mine Count: 30 mines
- Renderer: Emoji-based (DefaultCellRenderer)
You can customize the game by modifying main.py
:
# Create custom game configuration
app = create_minesweeper_app(
rows=20, # Grid height
cols=20, # Grid width
mine_count=50, # Number of mines
use_minimalist_renderer=True # Text-based theme
)
- DefaultCellRenderer: Modern emoji-based interface (๐ฃ๐ฉ)
- MinimalistCellRenderer: Text-based interface (M/F/X)
minesweeper-kivy/
โโโ main.py # Application entry point
โโโ game.py # Legacy game logic (for reference)
โโโ models/
โ โโโ minesweeper_model.py # Core game logic
โโโ views/
โ โโโ game_view.py # UI components
โโโ controllers/
โ โโโ game_controller.py # Input handling
โโโ interfaces/
โ โโโ game_interfaces.py # Abstract interfaces
โโโ utils/
โโโ cell_renderers.py # Rendering strategies
- Model-View-Controller (MVC): Clear separation of concerns
- Observer Pattern: Model notifies view of changes
- Strategy Pattern: Pluggable cell renderers
- Dependency Injection: Loose coupling between components
- Interface Segregation: Small, focused interfaces
# Add your test commands here when tests are implemented
python -m pytest tests/
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
- Follow PEP 8 guidelines
- Use type hints for all functions
- Document classes and methods
- Follow SOLID principles
Add screenshots of your game in action here
Game doesn't start:
- Ensure Python 3.7+ is installed
- Verify Kivy installation:
pip show kivy
No emoji display:
- Check if emoji font is available on your system
- Switch to minimalist renderer if needed
Performance issues:
- Try reducing grid size for older hardware
- Use minimalist renderer for better performance
- Difficulty presets (Beginner, Intermediate, Expert)
- High score tracking
- Timer functionality
- Sound effects
- Custom themes
- Multiplayer support
- Mobile touch optimization
This project is licensed under the MIT License - see the LICENSE file for details.
- Kivy team for the excellent framework
- Classic Minesweeper for the timeless gameplay
- Python community for design pattern inspiration
Enjoy the game! ๐ฃ