##############
# Area::Test #
##############

package Roguelike::Area::Test;

use strict;
use warnings;
use Roguelike::Game;
use Roguelike::Utility;

use Roguelike::Tilemap;
use Roguelike::Area;

sub generate {
  shift;  # We aren't really a class, no are we?
  my ($height, $width, $depth) = @_;
  my $map = new Roguelike::Tilemap $height, $width, " ";
  $_->{Hotspots} = [] foreach @{ $map->{Exits} };
  # Draw it out
  my $ls = [];
  foreach my $y (0 .. $map->height) {
    foreach my $x (0 .. $map->width) {
      if ($y == 0 or $y == $map->height or $x == 0 or $x == $map->width) {
        $map->{Map}[$y][$x]{_} = "#";
      } elsif ($y % 2 == 0 or $x % 2 == 0) {
        $map->{Map}[$y][$x]{_} = "#";
      } else {
        $map->{Map}[$y][$x]{_} = " ";
        push @$ls, [$y, $x];
      }
    }
  }
  use List::Util ("shuffle");
  foreach (1 .. 5) {
    my ($y, $x) = @{ delrand($ls) };
    foreach my $dir (shuffle(qw(h j k l))) {
      ($y, $x) = keycoords($dir, $y, $x);
      $map->{Map}[$y][$x]{_} = ".";
      ($y, $x) = keycoords($dir, $y, $x);
      $map->{Map}[$y][$x]{_} = ".";
    }
  }
  $map->quickdump; die;
  foreach (1 .. 50) { # Zzz
    while (1) {
      my $y = random(1, $height);
      my $x = random(1, $width);
      next unless $map->{Map}[$y][$x]{_} eq ".";
      next if $map->{Map}[$y][$x]{Hotspot};
      $map->{Map}[$y][$x]{Hotspot} = 1;
      push @{ $map->{Exits}[0]{Hotspots} }, [$y, $x];
      last;
    }
  }
  $map->refresh;
  return $map;
}

42;
