#!/usr/bin/perl use warnings; use strict; #package mapgenerator; my @dungeon = ('#') x 6400; sub generatemap { my $count; my $choice; my $increment = 0; my $notdoneyet = 1; my $start = int (rand(6399)); #chooses a random point to start building the maze my $specialfloor = shift; $dungeon[$start] = '.'; while($notdoneyet) { $choice = (-1, +1, -80, +80)[rand 4]; $start = $start + $choice; if ($start < 0 || $start > 6400) { redo; } elsif ($dungeon[$start] eq '#' && $dungeon[$start] + 1 eq '#' && $dungeon[$start] - 1 eq '#' && $dungeon[$start] + 80 eq '#' && $dungeon[$start] - 80 eq '#'){ $dungeon[$start] = '.'; } else { $increment++; if ($increment == 10) { $start = int (rand(6399)); $increment = 0; } } $count = grep m/./, @dungeon; if ($count == 3200) { $notdoneyet = 0; } } } sub printmap { my $first = 0; my $second = 80; my $totalprinted = 0; while ($totalprinted < 6400) { print $dungeon[$first..$second]; print "\n"; $first = $first + 80; $second = $second + 80; $totalprinted = $totalprinted + 80; } } generatemap; printmap;