Matt Owen

source code for "files/pe/grid.pm"

return to portfolio
  1.  package grid;
  2.  
  3.  sub new {
  4.   my $class = shift;
  5.   my $self = {
  6.   _width => shift,
  7.   _height => shift,
  8.   _default => shift,
  9.   _gird => {}
  10.   };
  11.  
  12.   bless $self, $class;
  13.   return $self;
  14.  }
  15.  
  16.  sub get {
  17.   my ($self, $x, $y, @rest) = @_;
  18.   my $pos = $x + $y*$self->{_width};
  19.  
  20.   return defined $self->{_grid}->{$pos} ? $self->{_grid}->{$pos} : $self->{_default};
  21.  }
  22.  
  23.  sub set {
  24.   my ($self, $x, $y, $val, @rest) = @_;
  25.   my $pos = $x + $y*$self->{_width};
  26.  
  27.   $self->{_grid}->{$pos} = $val;
  28.  }
  29.  
  30.  sub get_height {
  31.   my $self = shift;
  32.   return $self->{_height};
  33.  }
  34.  
  35.  sub get_width {
  36.   my $self = shift;
  37.   return $self->{_height};
  38.  }
  39.  
  40.  1;