package Games::Grid; require 5.005_62; use strict; use warnings; use Term::Cap; require POSIX; require Exporter; our @ISA = qw(Exporter); # Items to export into callers namespace by default. Note: do not export # names by default without a very good reason. Use EXPORT_OK instead. # Do not simply export all your public functions/methods/constants. # This allows declaration use Games::Grid ':all'; # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK # will save memory. our %EXPORT_TAGS = ( 'all' => [ qw( ) ] ); our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); our @EXPORT = qw( ); our $VERSION = '0.01'; sub top { $_[0]->{border} }; sub left { $_[0]->{border} }; sub clear_screen { $_[0]->{terminal}->Tgoto('cl', 0, 0, $_[0]->{FH}); } sub make_grid { my $self = shift; my $w = $self->can("right"); my $b = $self->can("bottom"); my $s = $self->can("scream"); warn "w,b,s: $w, $b, $s"; my ($border,$width,$height) = $self->{border}, $self->$w(), $self->$b(); warn " ($border,$width,$height) "; my $FH = $self->{FH}; my $terminal = $self->{terminal}; my $grid = $self->{grid}; for my $x ($border..$width-$border) { for my $y ($border..$height-$border) { $terminal->Tgoto('cm', $x, $y, $FH); print $grid; } } } sub new { my $class = shift; my %config = @_; my $self = { border => $config{border}, fill => $config{fill} }; { my $termios = new POSIX::Termios; $termios->getattr; my $ospeed = $termios->getospeed; $self->{terminal} = Tgetent Term::Cap { TERM => undef, OSPEED => $ospeed }; # require certain capabilities to be available $self->{terminal}->Trequire(qw/ce ku kd/); $self->{terminal}->{width} = $self->{terminal}->{_co}; $self->{terminal}->{height} = $self->{terminal}->{_li}; $self->{effective}{width} = $self->{terminal}->{width} - $self->{border}; $self->{effective}{height} = $self->{terminal}->{height} - $self->{border}; *{bottom} = $config{bottom}; *{Games::Grid::right} = $config{right}; } # Output Routines, if $FH is undefined these just return the string $self->{FH} = \*STDOUT; select(STDOUT); ++$|; bless $self, $class; } 1; __END__