Trag has asked for the wisdom of the Perl Monks concerning the following question:
#!/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 st +art 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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Writing a random dungeon generator in perl.
by xdg (Monsignor) on Aug 15, 2005 at 21:51 UTC | |
by xdg (Monsignor) on Aug 15, 2005 at 22:47 UTC | |
|
Re: Writing a random dungeon generator in perl.
by displeaser (Hermit) on Aug 16, 2005 at 10:05 UTC | |
by extremely (Priest) on Aug 16, 2005 at 14:23 UTC | |
|
Re: Writing a random dungeon generator in perl.
by kirbyk (Friar) on Aug 15, 2005 at 21:51 UTC | |
|
Re: Writing a random dungeon generator in perl.
by Trag (Monk) on Aug 15, 2005 at 22:48 UTC | |
by xdg (Monsignor) on Aug 16, 2005 at 08:14 UTC | |
|
Re: Writing a random dungeon generator in perl.
by GrandFather (Saint) on Aug 17, 2005 at 11:55 UTC |