From 91425983bfa5f1cbaf008c8252e961354102bc93 Mon Sep 17 00:00:00 2001 From: dakkar Date: Tue, 23 Nov 2010 23:03:04 +0000 Subject: more colours! --- lib/GridFiller.pm | 59 +++++++++++++++++++++++++++++-------------- lib/TextPrinter/ColourGrid.pm | 8 +++--- 2 files changed, 44 insertions(+), 23 deletions(-) diff --git a/lib/GridFiller.pm b/lib/GridFiller.pm index ebeb933..4ab25ac 100644 --- a/lib/GridFiller.pm +++ b/lib/GridFiller.pm @@ -90,18 +90,6 @@ has result => ( clearer => '_reset_result', ); -sub _build_result { - return [ - map { - [ - map { - [ ( $_ eq '*' ? 3 : 1 ), ' ' ], - } @$_ - ] - } @{shift->grid} - ]; -} - sub _reset { my ($self) = @_; @@ -190,16 +178,49 @@ sub _put_letter_at { return; } +{ +my %colourmap = ( + '*' => { + $HORIZONTAL => { + 0 => 1, + 1 => 2, + }, + $VERTICAL => { + 0 => 3, + 1 => 4, + }, + }, + ' ' => { + $HORIZONTAL => { + 0 => 5, + 1 => 6, + }, + $VERTICAL => { + 0 => 7, + 1 => 8, + }, + }, +); + +sub _build_result { + return [ + map { + [ + map { + [ $colourmap{$_}->{$HORIZONTAL}->{0}, ' ' ], + } @$_ + ] + } @{shift->grid} + ]; +} + sub _find_colour_for { my ($self,$x,$y,$dir) = @_; - # let's be easy - if ($dir == $HORIZONTAL) { - return $self->grid->[$y][$x] eq '*' ? 3 : 1; - } - else { - return $self->grid->[$y][$x] eq '*' ? 4 : 2; - } + return $colourmap{$self->grid->[$y][$x]}->{$dir}->{ + ($dir == $HORIZONTAL) ? ($y % 2) : ($x % 2) + }; +} } sub _find_place_for { diff --git a/lib/TextPrinter/ColourGrid.pm b/lib/TextPrinter/ColourGrid.pm index fdb9949..441956c 100644 --- a/lib/TextPrinter/ColourGrid.pm +++ b/lib/TextPrinter/ColourGrid.pm @@ -8,12 +8,12 @@ extends 'TextPrinter'; my @colours = ( color('reset'), # filler ( - map { color($_,'on_white') } - 'blue', 'green', + map { color($_,'on_black') } + 'dark yellow', 'dark green', 'dark red', 'dark white', ), ( - map { color($_,'on_black') } - 'dark yellow','dark green', + map { color($_,'on_white') } + 'blue', 'green', 'red', 'dark magenta', ), ); -- cgit v1.2.3