This commit is contained in:
Voldart 2023-04-23 16:04:48 +03:00 committed by GitHub
parent c4e187c132
commit ad8263292a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,88 +2,77 @@
namespace csharp namespace csharp
{ {
public class GildedRose namespace csharp
{ {
IList<Item> Items; public class GildedRose
public GildedRose(IList<Item> Items)
{ {
this.Items = Items; IList<Item> Items;
} public GildedRose(IList<Item> Items)
public void UpdateQuality()
{
for (var i = 0; i < Items.Count; i++)
{ {
if (Items[i].Name != "Aged Brie" && Items[i].Name != "Backstage passes to a TAFKAL80ETC concert") this.Items = Items;
}
public void UpdateQuality()
{
foreach (var item in Items)
{ {
if (Items[i].Quality > 0) UpdateItemQuality(item);
{ UpdateItemSellIn(item);
if (Items[i].Name != "Sulfuras, Hand of Ragnaros")
{
Items[i].Quality = Items[i].Quality - 1;
}
}
} }
else }
private void UpdateItemQuality(Item item)
{
if (item.Name == "Sulfuras, Hand of Ragnaros")
return;
if (item.Name == "Aged Brie")
{ {
if (Items[i].Quality < 50) IncreaseQuality(item);
{ if (item.SellIn < 0)
Items[i].Quality = Items[i].Quality + 1; IncreaseQuality(item);
return;
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") if (item.Name == "Backstage passes to a TAFKAL80ETC concert")
{ {
Items[i].SellIn = Items[i].SellIn - 1; IncreaseQuality(item);
if (item.SellIn <= 10)
IncreaseQuality(item);
if (item.SellIn <= 5)
IncreaseQuality(item);
if (item.SellIn < 0)
item.Quality = 0;
return;
} }
if (Items[i].SellIn < 0) DecreaseQuality(item);
{
if (Items[i].Name != "Aged Brie") if (item.SellIn < 0)
{ DecreaseQuality(item);
if (Items[i].Name != "Backstage passes to a TAFKAL80ETC concert") }
{
if (Items[i].Quality > 0) private void UpdateItemSellIn(Item item)
{ {
if (Items[i].Name != "Sulfuras, Hand of Ragnaros") if (item.Name != "Sulfuras, Hand of Ragnaros")
{ item.SellIn -= 1;
Items[i].Quality = Items[i].Quality - 1; }
}
} private void IncreaseQuality(Item item)
} {
else if (item.Quality < 50)
{ item.Quality += 1;
Items[i].Quality = Items[i].Quality - Items[i].Quality; }
}
} private void DecreaseQuality(Item item)
else {
{ if (item.Quality > 0)
if (Items[i].Quality < 50) item.Quality -= 1;
{
Items[i].Quality = Items[i].Quality + 1;
}
}
}
} }
} }
} }
} }