← Back to overview

mazeGenerator

View on GitHub 1

🎮 Maze Game

An interactive terminal-based maze generator and game written in Python. The project generates random mazes with animated visualization and allows players to navigate through the maze to reach the exit.

Generation Demo

✨ Features

  • Procedural maze generation: Automatic generation of unique mazes using a depth-first search algorithm
  • Live animation: Real-time visualization of the maze generation process with adjustable speed
  • Interactive gameplay: Navigate through the maze with simple keyboard controls
  • Terminal UI: Beautiful terminal display using the Rich library
  • Customizable size: Choose your own maze dimensions

🚀 Installation

Requirements

  • Python 3.10 or higher

Setup

  1. Clone the repository:
git clone https://github.com/Kobe-Erauw/mazeGenerator
cd mazeGenerator
  1. Install dependencies:
pip install -r requirements.txt

🎯 Usage

Start the game by running the main file:

python main.py

You will be prompted to enter:

  1. Height of the maze (number of characters)
  2. Width of the maze (number of characters)
  3. Animation duration (in seconds) - total time for the generation animation

Controls

  • z + Enter - Move up
  • s + Enter - Move down
  • d + Enter - Move right
  • q + Enter - Move left

Note: After each direction input, press Enter to confirm the move.

Objective

Navigate your character (X) from the starting position (top-left) to the destination (#, bottom-right). The game provides feedback when you attempt to move into a wall.

📁 Project Structure

maze-game/
│
├── main.py           # Application entry point
├── Field.py          # Contains Field class for maze management
├── Cell.py           # Contains Cell class for individual cells
├── Player.py         # Contains Player class for player logic
├── Position.py       # Contains Position and Direction classes
├── requirements.txt  # Python dependencies
└── README.md         # Project documentation

🔧 Technical Details

Classes

  • Field: Manages the playing field, generates the maze, and handles rendering
  • Cell: Represents an individual cell in the maze with walls and status
  • Player: Manages the player's position and movement
  • Position: Data class for x,y coordinates
  • Direction: Enum for the four movement directions

Algorithm

The project uses a recursive backtracking algorithm (depth-first search) for maze generation:

  1. Start at a random cell
  2. Mark the cell as visited
  3. Choose a random unvisited neighbor cell
  4. Remove the wall between the current cell and the chosen cell
  5. Recursively repeat for the chosen cell

📦 Dependencies

  • rich (14.2.0) - For terminal rendering and live updates
  • markdown-it-py (4.0.0) - Markdown parsing
  • Pygments (2.19.2) - Syntax highlighting support

🎨 Example Output

 ― ― ― ― ― ― ― ― ― ― ― ― ― ― ― ― ― ― ― ―
|X|       |     |     |     |           |
     ― ―     ―         ―     ― ―   ― ―
|   |     | | |   | |     |     |     | |
 ― ―   ― ―     ― ―   ― ― ― ― ―   ― ―
| |   |       |   | |         |       | |
     ―   ― ― ―       ―   ― ― ―   ― ― ―
|   |   |   |   | |   |         |   |   |
   ― ― ―       ―   ―   ―   ― ― ―     ― ―
|   |     |   | |   |   | |       |     |
 ―     ― ― ― ―   ―   ―   ―   ― ― ― ― ―
| |   |   |     | |   | |   |     |   | |
   ― ―   ―         ―       ―     ―
|   |       | | |   | |     | | |   |   |
       ― ― ―     ―     ― ―     ―   ― ―
| |   |   | | |     |   |     |   | |   |
   ― ―         ― ― ― ―   ― ―     ―     ―
|     | |   |   |     |   |   | |     | |
 ― ―     ―   ―     ―   ―   ― ―     ― ―
|       |     |     |           |      #|
 ― ― ― ― ― ― ― ― ― ― ― ― ― ― ― ― ― ― ― ―

📝 License

This project is open source and available under the MIT License.


Geniet van de animatie ❤️