Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 82 additions & 64 deletions src/Core/OriginalCode/UpdateQualityService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,79 +9,97 @@ namespace GildedRoseKata.OriginalCode;
public class UpdateQualityService(IList<Item> items)
{
#pragma warning disable
private const string AgedBrieName = "Aged Brie";
private const string SulfurasName = "Sulfuras, Hand of Ragnaros";
private const string BackstagePassesName = "Backstage passes to a TAFKAL80ETC concert";
private const int MaxQuality = 50;
private const int MinQuality = 0;

public void UpdateQuality()
{
for (var i = 0; i < items.Count; i++)
foreach (var item in items)
{
if (items[i].Name != "Aged Brie" && items[i].Name != "Backstage passes to a TAFKAL80ETC concert")
switch (item.Name)
{
if (items[i].Quality > 0)
{
if (items[i].Name != "Sulfuras, Hand of Ragnaros")
{
items[i].Quality = items[i].Quality - 1;
}
}
case AgedBrieName:
UpdateAgedBrie(item);
break;
case SulfurasName:
UpdateSulfuras(item);
break;
case BackstagePassesName:
UpdateBackstagePasses(item);
break;
default:
UpdateNormalItem(item);
break;
}
else
{
if (items[i].Quality < 50)
{
items[i].Quality = items[i].Quality + 1;
}
}

if (items[i].Name == "Backstage passes to a TAFKAL80ETC concert")
{
if (items[i].SellIn < 11)
{
if (items[i].Quality < 50)
{
items[i].Quality = items[i].Quality + 1;
}
}
private static void UpdateNormalItem(Item item)
{
DecreaseQuality(item);
item.SellIn--;

if (items[i].SellIn < 6)
{
if (items[i].Quality < 50)
{
items[i].Quality = items[i].Quality + 1;
}
}
}
}
}
if (item.SellIn < 0)
{
DecreaseQuality(item);
}
}

if (items[i].Name != "Sulfuras, Hand of Ragnaros")
{
items[i].SellIn = items[i].SellIn - 1;
}
private static void UpdateAgedBrie(Item item)
{
IncreaseQuality(item);
item.SellIn--;

if (items[i].SellIn < 0)
{
if (items[i].Name != "Aged Brie")
{
if (items[i].Name != "Backstage passes to a TAFKAL80ETC concert")
{
if (items[i].Quality > 0)
{
if (items[i].Name != "Sulfuras, Hand of Ragnaros")
{
items[i].Quality = items[i].Quality - 1;
}
}
}
else
{
items[i].Quality = items[i].Quality - items[i].Quality;
}
}
else
{
if (items[i].Quality < 50)
{
items[i].Quality = items[i].Quality + 1;
}
}
}
if (item.SellIn < 0)
{
IncreaseQuality(item);
}
}

private static void UpdateSulfuras(Item item)
{
// Sulfuras never has to be sold and never decreases in quality: nothing changes.
}

private static void UpdateBackstagePasses(Item item)
{
// The tier checks use SellIn as it was before today's decrement.
IncreaseQuality(item);

if (item.SellIn < 11)
{
IncreaseQuality(item);
}

if (item.SellIn < 6)
{
IncreaseQuality(item);
}

item.SellIn--;

if (item.SellIn < 0)
{
item.Quality = 0;
}
}

private static void IncreaseQuality(Item item)
{
if (item.Quality < MaxQuality)
{
item.Quality++;
}
}

private static void DecreaseQuality(Item item)
{
if (item.Quality > MinQuality)
{
item.Quality--;
}
}
#pragma warning restore
Expand Down
Loading