Commits

shl...@b384bcd7-cfd4-0310-aca0-d78b80f7b91b  committed 6573fa2

Add FinalLayoutObj->get_A_xy().

  • Participants
  • Parent commits e626dae

Comments (0)

Files changed (4)

File abc-path/Games-ABC_Path-Generator/lib/Games/ABC_Path/Generator.pm

     return;
 }
 
-sub _to_xy
-{
-    my ($self, $int) = @_;
-
-    return (($int / $LEN), ($int % $LEN));
-}
 
 sub _fisher_yates_shuffle {
     my ($self, $deck) = @_;

File abc-path/Games-ABC_Path-Generator/lib/Games/ABC_Path/Generator/Base.pm

     return $xy->[$Y] * $LEN + $xy->[$X];
 }
 
+sub _to_xy
+{
+    my ($self, $int) = @_;
+
+    return (($int / $LEN), ($int % $LEN));
+}
 =head1 SYNOPSIS
 
 B<For internal use.>.

File abc-path/Games-ABC_Path-Generator/lib/Games/ABC_Path/Generator/FinalLayoutObj.pm

     return index($self->_s, chr(1));
 }
 
+=head2 $layout->get_A_xy()
+
+Returns the (X,Y) coordinates of the letter A as a C<< {x => $x, y => $y} >>
+hash reference.
+
+=cut
+
+sub get_A_xy
+{
+    my ($self) = @_;
+
+    my ($y, $x) = $self->_to_xy($self->get_A_pos());
+
+    return {y => $y, x => $x,};
+}
+
 =head2 $layout->get_cell_contents($index)
 
 Returns the cell at index L<$index> (where index is C< $Y*5 + $X>).

File abc-path/Games-ABC_Path-Generator/t/riddle-obj.t

 use strict;
 use warnings;
 
-use Test::More tests => 4;
+use Test::More tests => 5;
+use Test::Differences;
 
 use Games::ABC_Path::Generator;
 
 
     # TEST
     is ($layout->get_A_pos(), 16, "A_pos is correct.");
+
+    # TEST
+    eq_or_diff(
+        $layout->get_A_xy(),
+        { y => 3, x => 1, },
+        "get_A_xy is ok."
+    );
 }