forked from DenLilleMand/gildedrose
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
164 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.idea/workspace.xml | ||
*.pyc | ||
/perl6/lib/.precomp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
use v6; | ||
|
||
use Item; | ||
|
||
class GildedRose { | ||
has Item @.items; | ||
|
||
method update_quality { | ||
for @!items -> $item { | ||
if ($item.name ne 'Aged Brie' && $item.name ne 'Backstage passes to a TAFKAL80ETC concert') { | ||
if ( $item.quality > 0 ) { | ||
if ( $item.name ne 'Sulfuras, Hand of Ragnaros' ) { | ||
$item.quality = $item.quality - 1; | ||
} | ||
} | ||
} | ||
else { | ||
if ( $item.quality < 50 ) { | ||
$item.quality = $item.quality + 1; | ||
|
||
if ( $item.name eq 'Backstage passes to a TAFKAL80ETC concert' ) | ||
{ | ||
if ( $item.sell_in < 11 ) { | ||
if ( $item.quality < 50 ) { | ||
$item.quality = $item.quality + 1; | ||
} | ||
} | ||
|
||
if ( $item.sell_in < 6 ) { | ||
if ( $item.quality < 50 ) { | ||
$item.quality = $item.quality + 1; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
if ( $item.name ne 'Sulfuras, Hand of Ragnaros' ) { | ||
$item.sell_in = $item.sell_in - 1; | ||
} | ||
|
||
if ( $item.sell_in < 0 ) { | ||
if ( $item.name ne 'Aged Brie' ) { | ||
if ( $item.name ne | ||
'Backstage passes to a TAFKAL80ETC concert' ) | ||
{ | ||
if ( $item.quality > 0 ) { | ||
if ( $item.name ne 'Sulfuras, Hand of Ragnaros' ) { | ||
$item.quality = $item.quality - 1; | ||
} | ||
} | ||
} | ||
else { | ||
$item.quality = $item.quality - $item.quality; | ||
} | ||
} | ||
else { | ||
if ( $item.quality < 50 ) { | ||
$item.quality = $item.quality + 1; | ||
} | ||
} | ||
} | ||
} | ||
return; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use v6; | ||
|
||
class Item { | ||
has Str $.name; | ||
has Int $.sell_in is rw = 0; | ||
has Int $.quality is rw = 0; | ||
|
||
method Str { | ||
"{$!name}, {$!sell_in}, {$!quality}" | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/env perl6 | ||
|
||
use v6; | ||
use Test; | ||
use lib 'lib'; | ||
|
||
use GildedRose; | ||
use Item; | ||
|
||
my $item = Item.new(:name<foo>); | ||
my $app = GildedRose.new(items => ($item)); | ||
|
||
$app.update_quality(); | ||
is $app.items[0].name, 'fixme', "first day pass"; | ||
|
||
done-testing; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#!/usr/bin/env perl6 | ||
|
||
use v6; | ||
|
||
use lib 'lib'; | ||
|
||
use GildedRose; | ||
use Item; | ||
|
||
print 'OMGHAI!', "\n"; | ||
my @items = ( | ||
Item.new( | ||
name => '+5 Dexterity Vest', | ||
sell_in => 10, | ||
quality => 20 | ||
), | ||
Item.new( | ||
name => 'Aged Brie', | ||
sell_in => 2, | ||
quality => 0 | ||
), | ||
Item.new( | ||
name => 'Elixir of the Mongoose', | ||
sell_in => 5, | ||
quality => 7 | ||
), | ||
Item.new( | ||
name => 'Sulfuras, Hand of Ragnaros', | ||
sell_in => 0, | ||
quality => 80 | ||
), | ||
Item.new( | ||
name => 'Sulfuras, Hand of Ragnaros', | ||
sell_in => -1, | ||
quality => 80 | ||
), | ||
Item.new( | ||
name => 'Backstage passes to a TAFKAL80ETC concert', | ||
sell_in => 15, | ||
quality => 20 | ||
), | ||
Item.new( | ||
name => 'Backstage passes to a TAFKAL80ETC concert', | ||
sell_in => 10, | ||
quality => 49 | ||
), | ||
Item.new( | ||
name => 'Backstage passes to a TAFKAL80ETC concert', | ||
sell_in => 5, | ||
quality => 49 | ||
), | ||
Item.new( # This Conjured item does not work properly yet | ||
name => 'Conjured Mana Cake', | ||
sell_in => 3, | ||
quality => 6 | ||
), | ||
); | ||
|
||
sub MAIN(Int $days = 2) { | ||
my $gilded-rose = GildedRose.new( items => @items ); | ||
for ^$days -> $day { | ||
say "-------- day $day --------"; | ||
say 'name, sellIn, quality'; | ||
|
||
.Str.say for $gilded-rose.items; | ||
|
||
"".say; | ||
$gilded-rose.update_quality(); | ||
} | ||
} |