refactoring first pass

This commit is contained in:
OKinane 2023-03-11 15:08:31 +01:00
parent 498786b31e
commit d2bf4e2f7e

View File

@ -14,68 +14,64 @@ namespace GildedRoseKata
{ {
for (var i = 0; i < Items.Count; i++) for (var i = 0; i < Items.Count; i++)
{ {
if (Items[i].Name != "Aged Brie" && Items[i].Name != "Backstage passes to a TAFKAL80ETC concert") if (Items[i].Name == "Sulfuras, Hand of Ragnaros")
{ {
if (Items[i].Quality > 0) continue;
{
if (Items[i].Name != "Sulfuras, Hand of Ragnaros")
{
Items[i].Quality = Items[i].Quality - 1;
}
}
}
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;
}
} }
if (Items[i].SellIn < 6)
{
if (Items[i].Quality < 50)
{
Items[i].Quality = Items[i].Quality + 1;
}
}
}
}
}
if (Items[i].Name != "Sulfuras, Hand of Ragnaros")
{
Items[i].SellIn = Items[i].SellIn - 1; Items[i].SellIn = Items[i].SellIn - 1;
}
if (Items[i].Name == "Aged Brie")
{
IncreaseQualityByOne(i);
if (Items[i].SellIn < 0) if (Items[i].SellIn < 0)
{ {
if (Items[i].Name != "Aged Brie") IncreaseQualityByOne(i);
}
}
else if (Items[i].Name == "Backstage passes to a TAFKAL80ETC concert")
{ {
if (Items[i].Name != "Backstage passes to a TAFKAL80ETC concert") IncreaseBackstageQuality(i);
if (Items[i].SellIn < 0)
{
Items[i].Quality = 0;
}
}
else
{
DecreaseQualityByOne(i);
if (Items[i].SellIn < 0)
{
DecreaseQualityByOne(i);
}
}
}
}
private void IncreaseBackstageQuality(int i)
{
IncreaseQualityByOne(i);
if (Items[i].SellIn < 10)
{
IncreaseQualityByOne(i);
}
if (Items[i].SellIn < 5)
{
IncreaseQualityByOne(i);
}
}
private void DecreaseQualityByOne(int i)
{ {
if (Items[i].Quality > 0) if (Items[i].Quality > 0)
{
if (Items[i].Name != "Sulfuras, Hand of Ragnaros")
{ {
Items[i].Quality = Items[i].Quality - 1; Items[i].Quality = Items[i].Quality - 1;
} }
} }
}
else private void IncreaseQualityByOne(int i)
{
Items[i].Quality = Items[i].Quality - Items[i].Quality;
}
}
else
{ {
if (Items[i].Quality < 50) if (Items[i].Quality < 50)
{ {
@ -84,6 +80,3 @@ namespace GildedRoseKata
} }
} }
} }
}
}
}