File Coverage

blib/lib/Term/Maze.pm
Criterion Covered Total %
statement 11 27 40.7
branch 0 4 0.0
condition n/a
subroutine 4 6 66.6
pod 2 2 100.0
total 17 39 43.5


line stmt bran cond sub pod time code
1             package Term::Maze;
2              
3 1     1   122240 use 5.006;
  1         3  
4 1     1   10 use strict;
  1         2  
  1         34  
5 1     1   6 use warnings;
  1         1  
  1         87  
6 1     1   599 use Term::ReadKey;
  1         3950  
  1         388  
7             our $VERSION = '0.04';
8              
9             require XSLoader;
10             XSLoader::load('Term::Maze', $VERSION);
11              
12             sub run {
13 0     0 1   my ($self, $width, $height) = @_;
14 0           ReadMode("cbreak");
15 0           my $maze = Term::Maze->new($width, $height);
16 0           $maze->refresh();
17 0           while (!$maze->at_exit) {
18 0           my $key = ReadKey(0);
19 0 0         next unless defined $key;
20 0 0         if ($key =~ m/^[wasdhjkl]$/){
21 0           $maze->move_player($key);
22             }
23 0           $maze->refresh();
24             }
25 0           print "You win!\n";
26             }
27              
28             sub refresh {
29 0     0 1   my ($self) = @_;
30 0           print "\e[H\e[2J";
31 0           my $rows = $self->get_maze_with_player();
32 0           print "$_\n" for @$rows;
33 0           print "Use WASD or HJKL to move. Reach the exit to win.\n";
34             }
35              
36             1;
37              
38             __END__