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__
####
use Games::Grid;
my $g = Games::Grid->new
(border => 4,
right => sub { $_[0]->{effective}{width} },
bottom => sub { $_[0]->{effective}{height} },
fill => '=');
# $g->clear_screen;
warn sprintf
"T: %d B: %d L: %d R: %d", $g->top, $g->bottom, $g->left, $g->right;
my $b = $g->can("bottom");
my $r = $g->can("right");
warn sprintf
"r: $r, b: $b... %d, %d", $g->$b(), $g->$r();
$g->make_grid;
####
PERL_DL_NONLAZY=1 /arudev/bin/perl -Iblib/arch -Iblib/lib -I/arudev/lib/perl5/5.6.0/sun4-solaris -I/arudev/lib/perl5/5.6.0 test.pl
1..1
ok 1
T: 4 B: 20 L: 4 R: 76 at test.pl line 29.
r: CODE(0x174768), b: CODE(0x18f480)... 20, 76 at test.pl line 35.
Use of uninitialized value in concatenation (.) at blib/lib/Games/Grid.pm line 49.
w,b,s: CODE(0x174768), CODE(0x18f480), at blib/lib/Games/Grid.pm line 49.
Use of uninitialized value in concatenation (.) at blib/lib/Games/Grid.pm line 56.
Use of uninitialized value in concatenation (.) at blib/lib/Games/Grid.pm line 56.
(4,,) at blib/lib/Games/Grid.pm line 56.
Use of uninitialized value in subtraction (-) at blib/lib/Games/Grid.pm line 61.
{ap555sun:tmbranno:tmbranno_1674066_sql_memory_hogging:arupatch}115> /home/tmbranno/src/Games/Grid[61C
%