Refactoring - extract UpdateQuality(Item) to method

This commit is contained in:
Sarah Ashri 2024-03-12 13:40:35 +10:00
parent 4f9209d154
commit 4684969140

View File

@ -12,75 +12,77 @@ namespace csharp
public void UpdateQuality() public void UpdateQuality()
{ {
for (var i = 0; i < Items.Count; i++) Items.ForEach(item => UpdateQuality(item));
}
private void UpdateQuality(Item item)
{
if (item.Name != "Aged Brie" && item.Name != "Backstage passes to a TAFKAL80ETC concert")
{ {
if (Items[i].Name != "Aged Brie" && Items[i].Name != "Backstage passes to a TAFKAL80ETC concert") if (item.Quality > 0)
{ {
if (Items[i].Quality > 0) if (item.Name != "Sulfuras, Hand of Ragnaros")
{ {
if (Items[i].Name != "Sulfuras, Hand of Ragnaros") item.Quality = item.Quality - 1;
{
Items[i].Quality = Items[i].Quality - 1;
}
} }
} }
else }
else
{
if (item.Quality < 50)
{ {
if (Items[i].Quality < 50) item.Quality = item.Quality + 1;
if (item.Name == "Backstage passes to a TAFKAL80ETC concert")
{ {
Items[i].Quality = Items[i].Quality + 1; if (item.SellIn < 11)
if (Items[i].Name == "Backstage passes to a TAFKAL80ETC concert")
{ {
if (Items[i].SellIn < 11) if (item.Quality < 50)
{ {
if (Items[i].Quality < 50) item.Quality = item.Quality + 1;
{
Items[i].Quality = Items[i].Quality + 1;
}
} }
}
if (Items[i].SellIn < 6) if (item.SellIn < 6)
{
if (item.Quality < 50)
{ {
if (Items[i].Quality < 50) item.Quality = item.Quality + 1;
{
Items[i].Quality = Items[i].Quality + 1;
}
} }
} }
} }
} }
}
if (Items[i].Name != "Sulfuras, Hand of Ragnaros") if (item.Name != "Sulfuras, Hand of Ragnaros")
{ {
Items[i].SellIn = Items[i].SellIn - 1; item.SellIn = item.SellIn - 1;
} }
if (Items[i].SellIn < 0) if (item.SellIn < 0)
{
if (item.Name != "Aged Brie")
{ {
if (Items[i].Name != "Aged Brie") if (item.Name != "Backstage passes to a TAFKAL80ETC concert")
{ {
if (Items[i].Name != "Backstage passes to a TAFKAL80ETC concert") if (item.Quality > 0)
{ {
if (Items[i].Quality > 0) if (item.Name != "Sulfuras, Hand of Ragnaros")
{ {
if (Items[i].Name != "Sulfuras, Hand of Ragnaros") item.Quality = item.Quality - 1;
{
Items[i].Quality = Items[i].Quality - 1;
}
} }
} }
else
{
Items[i].Quality = Items[i].Quality - Items[i].Quality;
}
} }
else else
{ {
if (Items[i].Quality < 50) item.Quality = item.Quality - item.Quality;
{ }
Items[i].Quality = Items[i].Quality + 1; }
} else
{
if (item.Quality < 50)
{
item.Quality = item.Quality + 1;
} }
} }
} }