#!/ASPerl/bin/perl use strict; use Klax; use Data::Dumper; my $game = new Klax::Game ("width" => 5, "height" => 5, "ssize" => 5, "depth" => 10); #print Dumper ($game), "\n"; render ($game); <>; my $suc = $game->popdown; render ($game); print "(pop failed)\n" unless ($suc); sub render { my $game = shift; render_grid ($game->{"grid"}); render_stack ($game->{"stack"}); render_board ($game->{"board"}); } sub render_grid { # # --------------------- # | 0 | | | 4 | | # |---+---+---+---+---| # | | 1 | | | | # |---+---+---+---+---| # | | | | | 5 | # my $g = shift; my $row; my $col; print " -"; print "----" for (1..$g->{"width"}); print "\n"; for ($row = $g->{"height"} - 1; $row > 0; $row--) { my $cs = sprintf (" %2d ", $row); print "$cs|"; for $col (0..($g->{"width"} - 1)) { print " ", $g->{'data'}->[$col]->[$row], " |"; } print "\n"; print " |"; print "---+" for (2..$g->{"width"}); print "---|\n"; } print " 0 |"; for $col (0..($g->{"width"} - 1)) { print " ", $g->{"data"}->[$col]->[0], " |"; } print "\n"; print " -"; print "----" for (1..$g->{"width"}); print "\n"; } sub render_stack { # # --- # | | # |---| # | | # |---| # | | # |---| # | | # my $s = shift; my $nline = 0; my @dl = @{$s->{"data"}}; if (@dl) { print " "; print " " x (4 * $s->{"pos"}); print " ---\n"; $nline++; my $lst = pop (@dl); for my $nm (@dl) { print " "; print " " x (4 * $s->{"pos"}); print "| ", $nm, " |\n"; $nline++; print " "; print " " x (4 * $s->{"pos"}); print "|---|\n"; $nline++; } print " "; print " " x (4 * $s->{"pos"}); print "| ", $lst, " |\n"; $nline++; # print " "; # print " " x (4 * $s->{"pos"}); # print "-----\n"; $nline++; } else { print "\n"; $nline++; print "\n"; $nline++; } print " " x (4 * $s->{"pos"}); print " ----- \n"; $nline++; print "\n" x (12 - $nline); } sub render_board { my $b = shift; render_grid ($b); }