NAME
Term::Maze - Mazes in the terminal
VERSION
Version 0.06
SYNOPSIS
use Term::Maze;
Term::Maze->run(40, 20);
...
#########################################
#S# # # # # #
# # # ### # # ### ####### ####### # # # #
# # # # # # # # # # # #
# # # # ### ### ####### ### ######### # #
# # # # # # # # # # # # #
# # # # # ### ####### ### ### # # ##### #
# # # # # # # # # # # #
# # # ####### ### ##### ### ### # # # ###
# # # # # # # # # # #
######### # ### ### # ### ######### ### #
# # # @# # # # # #
# ########### ### # ### ### # # # ### ###
# # # # # # # # # # # #
### # ######### # ####### # # ##### # # #
# # # # # # # # # #
# ############# # # ### # ##### # ##### #
# # # # # # # # #
############# ######### ##### # # # # ###
# # # # E#
#########################################
Use WASD to move. Reach the exit to win.
SUBROUTINES/METHODS
options
my $fields = Term::Maze->options;
The options a person would set before a game, in the order a launcher shows them. Each is a hash reference with a name, a type and a help, and min and max or choices where the type has them. A new list is returned each time.
width-
A whole number from 5 to 120: cells across.
height-
A whole number from 5 to 60: cells down.
run
Term::Maze->run(40, 20);
exit Term::Maze->run(@ARGV);
Runs the maze game and returns the exit status. Two bare non-negative integers are the width and height, as they always were; anything else is read as options: --width N and --height N (defaults 40 and 20, each at least 2) and --help, which prints the usage on STDOUT and returns 0. A bad option prints the usage on STDERR and returns 2.
The terminal is put into cbreak mode for the game and restored on every way out: on reaching the exit, on quitting, after a die, and from INT, TERM and HUP, whose handlers are local to the call and re-raise once the mode is back. Move with WASD or HJKL; q or escape quits with status 0, and reaching the exit prints "You win!" and returns 0.
refresh
Refreshes the maze display in the terminal. It clears the screen, retrieves the maze with the player's position, and prints it to the terminal.
$maze->refresh();
new
Instantiate a new Term::Maze object with the specified width and height. This method initializes the maze structure, player position, and exit point.
my $maze = Term::Maze->new($width, $height);
move_player
Moves the player in the maze based on the input key. The player can move up, down, left, or right using the WASD keys. It checks for valid moves and updates the player's position accordingly.
$maze->move_player('w'); # Move up
$maze->move_player('a'); # Move left
$maze->move_player('s'); # Move down
$maze->move_player('d'); # Move right
get_maze_with_player
Returns the maze structure with the player's current position. It generates a 2D array representation of the maze, including walls, paths, the player, and the exit.
my $rows = $maze->get_maze_with_player();
at_exit
Checks if the player has reached the exit point in the maze. It compares the player's current position with the exit coordinates.
my $at_exit = $maze->at_exit;
AUTHOR
LNATION, <email at lnation.org>
BUGS
Please report any bugs or feature requests to bug-term-maze at rt.cpan.org, or through the web interface at https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Term-Maze. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Term::Maze
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
Search CPAN
ACKNOWLEDGEMENTS
LICENSE AND COPYRIGHT
This software is Copyright (c) 2025 by LNATION.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)