SVG/Hex.pm

filter: Statementstmt 100% 34 / 34 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 100% 4 / 4 totaltotal 100% 51 / 51 CC 3 SCAR 4.4
CC
3
Cov
100%
convert_sign_position
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.5
« SVG/Rect.pm ↑ Summary SVG/RectHex.pm »
1 # SVG maze output
2 # Performs transformation, cleanup, and printing of output of Games::Maze
3  
4 package Games::Maze::SVG::Hex;
5  
6 28 ▶use base Games::Maze::SVG::HexCells;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 28 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 28 ▶use Games::Maze;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 28 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 28 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 =head1 NAME
14  
15 Games::Maze::SVG::Hex - Build hexagonal mazes in SVG.
16  
17 =head1 VERSION
18  
19 Version 0.90
20  
21 =cut
22  
23 28 our $VERSION = 0.90;
24  
25 =head1 SYNOPSIS
26  
27 Games::Maze::SVG::Hex uses the Games::Maze module to create hexagonal mazes in
28 SVG.
29  
30 use Games::Maze::SVG;
31  
32 my $foo = Games::Maze::SVG->new( 'Hex' );
33 ...
34  
35 =cut
36  
37 =head1 FUNCTIONS
38  
39 =cut
40  
41 # ----------------------------------------------
42 # Subroutines
43  
44 =over 4
45  
46 =item new
47  
48 Create a new Games::Maze::SVG object. Supports the following named parameters:
49  
50 Takes one positional parameter that is the maze type: Rect, RectHex, or Hex
51  
52 =over 4
53  
54 =item wallform
55  
56 String naming the wall format. Legal values are bevel, round, roundcorners,
57 and straight.
58  
59 =item crumb
60  
61 String describing the breadcrumb design. Legal values are dash,
62 dot, line, and none
63  
64 =item dx
65  
66 The size of the tiles in the X direction.
67  
68 =item dy
69  
70 The size of the tiles in the Y direction.
71  
72 =item dir
73  
74 Directory in which to find the ecmascript for the maze interactivity. Should
75 either be relative, or in URL form.
76  
77 =back
78  
79 =cut
80  
81 sub new
82 8 ▶{
Subroutine new: called CC=1 SCAR=0.0
Pod documented
83 8 my $class = shift;
84  
85 8 my $obj = Games::Maze::SVG::HexCells->new( @_ );
86 7 $obj->{mazeparms}->{form} = 'Hexagon';
87  
88 # rebless into this class.
89 7 return bless $obj, $class;
90 }
91  
92  
93 =item is_hex
94  
95 Method returns true.
96  
97 =cut
98  
99 sub is_hex
100 1 ▶{
Subroutine is_hex: called CC=1 SCAR=0.0
Pod documented
101 1 return 1;
102 }
103  
104  
105 =item is_hex_shaped
106  
107 Method returns true.
108  
109 =cut
110  
111 sub is_hex_shaped
112 1 ▶{
Subroutine is_hex_shaped: called CC=1 SCAR=0.0
Pod documented
113 1 return 1;
114 }
115  
116  
117 =item convert_sign_position
118  
119 Convert the supplied x and y coordinates into the appropriate real coordinates
120 for a the position of the exit sign.
121  
122 =over 4
123  
124 =item $x x coord from the maze
125  
126 =item $y y coord from the maze
127  
128 =back
129  
130 returns a two element list containing (x, y).
131  
132 =cut
133  
134 sub convert_sign_position
135 6 ▶{
Subroutine convert_sign_position: called CC=3 SCAR=11.0
Pod documented
136 6 my $self = shift;
137 6 my ($x, $y) = @_;
138  
139 6 $x *= $self->dx();
140 6 $y *= $self->dy();
141  
142 # left or right
143 6 ▶ if($x > $self->{width}/2)
Branch: 1 branch
BranchTrueFalseTotal
if ($x > $self->{'width'} / 2) { } 4 2 6
144 {
145 4 $x += $self->dx();
146 }
147 else
148 {
149 2 $x -= $self->dx();
150 }
151  
152 # adjust bottom
153 6 ▶ if($y > $self->{height}/2)
Branch: 1 branch
BranchTrueFalseTotal
if ($y > $self->{'height'} / 2) { } 4 2 6
154 {
155 4 $y += 3*$self->dy();
156 }
157 else
158 {
159 2 $y -= $self->dy();
160 }
161  
162 6 return ($x, $y);
163 }
164  
165 =back
166  
167 =head1 AUTHOR
168  
169 G. Wade Johnson, C<< <wade@anomaly.org> >>
170  
171 =head1 BUGS
172  
173 Please report any bugs or feature requests to
174 C<bug-game-maze-svg@rt.cpan.org>, or through the web interface at
175 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Game-Maze-SVG>.
176 I will be notified, and then you'll automatically be notified of progress on
177 your bug as I make changes.
178  
179 =head1 ACKNOWLEDGEMENTS
180  
181 Thanks go to Valen Johnson and Jason Wood for extensive test play of the
182 mazes.
183  
184 =head1 COPYRIGHT & LICENSE
185  
186 Copyright 2004-2006 G. Wade Johnson, all rights reserved.
187  
188 This program is free software; you can redistribute it and/or modify it
189 under the same terms as Perl itself.
190  
191 =cut
192  
193 28 1;
« SVG/Rect.pm ↑ Summary SVG/RectHex.pm »