Maze Game Library
A simple Rust library for creating and playing text-based maze games. The maze is procedurally generated, and the player must find their way from the entrance to the exit.
Features
- Randomly generated mazes
- Simple text-based UI
- Keyboard controls for character movement
- Can be used as a library or standalone game
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Usage as a Library
use Maze;
Playing the Game
Execute the following command to run the standalone game:
cargo run
Controls
wor up: Move upsor down: Move downaor left: Move leftdor right: Move rightq: Quit the game
Project Structure
lib.rs: Public module exportsmain.rs: Standalone game loop and user input handlingmaze.rs: Maze data structure and operationsgenerator.rs: Maze generation algorithmsposition.rs: Position structure
Algorithm
The maze is generated using a "recursive backtracking" algorithm (also known as the "digging method"). This algorithm works as follows:
- Fill the entire maze with walls
- Start at a specific point and mark it as a passage
- Choose a random direction and, if the cell two spaces away is a wall, convert it and the wall between to passages
- Recursively repeat step 3 from the newly created passage
This creates a complex maze with dead ends and branching paths.
License
This project is licensed under the MIT License - see the LICENSE file for details.