refactor: refactoring updateQuality logic

This commit is contained in:
MatheusMW21 2025-09-02 20:47:26 -03:00
parent 5eba76c569
commit a3cdf07cec

View File

@ -13,77 +13,50 @@ public class GildedRose
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")
if (item.Name == "Sulfuras, Hand of Ragnaros")
continue;
item.SellIn--;
switch (item.Name)
{
if (Items[i].Quality > 0)
{
if (Items[i].Name != "Sulfuras, Hand of Ragnaros")
case "Aged Brie":
IncreaseQuality(item);
if (item.SellIn < 0)
IncreaseQuality(item);
break;
case "Backstage passes to a TAFKAL80ETC concert":
if (item.SellIn < 0)
{
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;
}
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;
}
}
item.Quality = 0;
}
else
{
Items[i].Quality = Items[i].Quality - Items[i].Quality;
IncreaseQuality(item);
if (item.SellIn < 10) IncreaseQuality(item);
if (item.SellIn < 5) IncreaseQuality(item);
}
}
else
{
if (Items[i].Quality < 50)
{
Items[i].Quality = Items[i].Quality + 1;
}
}
break;
default:
DecreaseQuality(item);
if (item.SellIn < 0)
DecreaseQuality(item);
break;
}
}
}
private void IncreaseQuality(Item item)
{
if (item.Quality < 50) item.Quality++;
}
private void DecreaseQuality(Item item)
{
if (item.Quality > 0) item.Quality--;
}
}