maze_runner_rs 0.1.0

A simple text-based maze game library
Documentation
  • Coverage
  • 88.89%
    24 out of 27 items documented0 out of 12 items with examples
  • Size
  • Source code size: 18.45 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 997.88 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 16s Average build duration of successful builds.
  • all releases: 16s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • enumura1/maze_runner_rs
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • enumura1

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:

[dependencies]
maze_game = "0.1.0"

Usage as a Library

use maze_game::maze::Maze;

fn main() {
    // Create a new maze
    let mut maze = match Maze::create() {
        Some(m) => m,
        None => {
            println!("Failed to generate the maze.");
            return;
        }
    };

    // Display the maze
    println!("{}", maze.get_maze_as_string());

    // Try to move the player
    let moved = maze.try_move("d"); // Move right
    
    // Check if the game is completed
    let state = maze.get_state();
    if state.is_completed {
        println!("Congratulations! You've reached the goal!");
    }
}

Playing the Game

Execute the following command to run the standalone game:

cargo run

Controls

  • w or up: Move up
  • s or down: Move down
  • a or left: Move left
  • d or right: Move right
  • q: Quit the game

Project Structure

  • lib.rs: Public module exports
  • main.rs: Standalone game loop and user input handling
  • maze.rs: Maze data structure and operations
  • generator.rs: Maze generation algorithms
  • position.rs: Position structure

Algorithm

The maze is generated using a "recursive backtracking" algorithm (also known as the "digging method"). This algorithm works as follows:

  1. Fill the entire maze with walls
  2. Start at a specific point and mark it as a passage
  3. Choose a random direction and, if the cell two spaces away is a wall, convert it and the wall between to passages
  4. 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.