A classic Minesweeper game implementation in Python with a command-line interface. Features multiple difficulty levels, custom game options, and a fully functional game engine.
✨ Multiple Difficulty Levels
- Easy: 8×8 board with 10 mines
- Medium: 10×10 board with 10 mines
- Hard: 12×12 board with 40 mines
- Expert: 16×16 board with 99 mines
- Custom: Define your own board size and mine count
🎯 Core Gameplay
- Reveal cells to find safe areas
- Flag suspected mines
- Flood-fill algorithm for auto-revealing empty areas
- Move counter and game statistics
- Win/lose detection
🔧 Technical Features
- Object-oriented design with separate Board and Game classes
- Input validation and error handling
- Clear command-line interface with ASCII art
- No external dependencies (uses only Python standard library)
minesweeper/
├── main.py # Game entry point and UI
├── src/
│ ├── game.py # Game controller logic
│ ├── board.py # Board management and cell logic
│ └── __init__.py # Package initialization
├── requirements.txt # Dependencies (none required)
└── README.md # This file
- Python 3.7 or higher
- Navigate to the project directory:
cd minesweeper- (Optional) Create a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- No external dependencies to install! The game uses only Python's standard library.
python main.pyReveal a cell:
row col
Example: 3 5 - reveals cell at row 3, column 5
Flag a cell:
row col f
Example: 2 2 f - flags cell at row 2, column 2
Other commands:
help- Display instructionsnew- Start a new gamequitorexit- Exit the game
| Symbol | Meaning |
|---|---|
● |
Hidden cell |
💣 |
Mine (revealed) |
🚩 |
Flagged cell |
0-8 |
Number of adjacent mines |
(space) |
Safe area with no adjacent mines |
- Start in the middle - This often gives you the most information
- Use logic - If a cell shows "2" and two adjacent cells are flagged, other neighbors are safe
- Flag strategically - Mark cells you suspect are mines to avoid clicking them
- Watch for patterns - Empty areas (0 adjacent mines) automatically expand
- Take your time - There's no timer, so think before you click!
──────────────────────────────────────────────────────────────
0 1 2 3 4 5 6 7 8 9
──────────────────────────────────────────────────────────────
0 | ● ● ● ● ● ● ● ● ● ●|
1 | ● ● ● ● ● ● ● ● ● ●|
2 | ● ● ● ● ● ● ● ● ● ●|
3 | ● ● ● ● ● ● ● ● ● ●|
4 | ● ● ● ● ● ● ● ● ● ●|
5 | ● ● ● ● ● ● ● ● ● ●|
6 | ● ● ● ● ● ● ● ● ● ●|
7 | ● ● ● ● ● ● ● ● ● ●|
8 | ● ● ● ● ● ● ● ● ● ●|
9 | ● ● ● ● ● ● ● ● ● ●|
──────────────────────────────────────────────────────────────
┌─ STATS ─────────────────────┐
│ Difficulty: Easy │
│ Moves: 0 │
│ Mines: 10 │
│ Flagged: 0 │
│ Remaining: 10 │
│ Unrevealed: 100 │
└──────────────────────────────┘
Enter move (row col) [or 'help']: 5 5
- Cell: Represents a single board cell with mine status, reveal state, and flag state
- Board: Manages the game board, mine placement, and cell logic
- Flood-fill algorithm for revealing safe areas
- Adjacent mine calculation
- Win condition detection
- Game: High-level game controller
- Move processing
- Game state management
- Statistics tracking
- Difficulty level detection
- User interface and game loop
- Input parsing and validation
- Menu system
- Game display and formatting
Mines are randomly placed on the board to ensure variety and replayability.
When you reveal a cell with no adjacent mines, the game automatically reveals all connected empty areas, making the game flow smoother.
Track your progress with:
- Move counter
- Flagged mines count
- Remaining unrevealed cells
- Game difficulty level
- 🎨 GUI version using Tkinter or PyGame
- ⏱️ Timer functionality
- 🏆 Leaderboard/high scores
- 🎯 Difficulty presets with time challenges
- 💾 Save/load game functionality
- 🌓 Dark mode theme
- Pure Python implementation with no external dependencies
- Follows PEP 8 style guidelines
- Type hints included for better code clarity
- Comprehensive docstrings for all functions
This project is open source and available for educational purposes.
Created as a classic game implementation in Python.
Enjoy playing Minesweeper! 🎮