mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-10 12:11:20 +00:00
refactor: refactoring updateQuality logic
This commit is contained in:
parent
5eba76c569
commit
a3cdf07cec
@ -13,77 +13,50 @@ public class GildedRose
|
|||||||
|
|
||||||
public void UpdateQuality()
|
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)
|
case "Aged Brie":
|
||||||
{
|
IncreaseQuality(item);
|
||||||
if (Items[i].Name != "Sulfuras, Hand of Ragnaros")
|
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;
|
item.Quality = 0;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Items[i].Quality = Items[i].Quality - Items[i].Quality;
|
IncreaseQuality(item);
|
||||||
|
if (item.SellIn < 10) IncreaseQuality(item);
|
||||||
|
if (item.SellIn < 5) IncreaseQuality(item);
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
else
|
|
||||||
{
|
default:
|
||||||
if (Items[i].Quality < 50)
|
DecreaseQuality(item);
|
||||||
{
|
if (item.SellIn < 0)
|
||||||
Items[i].Quality = Items[i].Quality + 1;
|
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--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user