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

@ -1,5 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
namespace csharp
{
namespace csharp namespace csharp
{ {
public class GildedRose public class GildedRose
@ -12,78 +14,65 @@ namespace csharp
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") UpdateItemQuality(item);
{ UpdateItemSellIn(item);
if (Items[i].Quality > 0)
{
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) private void UpdateItemQuality(Item item)
{ {
if (Items[i].Quality < 50) if (item.Name == "Sulfuras, Hand of Ragnaros")
return;
if (item.Name == "Aged Brie")
{ {
Items[i].Quality = Items[i].Quality + 1; IncreaseQuality(item);
if (item.SellIn < 0)
IncreaseQuality(item);
return;
} }
if (item.Name == "Backstage passes to a TAFKAL80ETC concert")
{
IncreaseQuality(item);
if (item.SellIn <= 10)
IncreaseQuality(item);
if (item.SellIn <= 5)
IncreaseQuality(item);
if (item.SellIn < 0)
item.Quality = 0;
return;
} }
DecreaseQuality(item);
if (item.SellIn < 0)
DecreaseQuality(item);
}
private void UpdateItemSellIn(Item item)
{
if (item.Name != "Sulfuras, Hand of Ragnaros")
item.SellIn -= 1;
}
private void IncreaseQuality(Item item)
{
if (item.Quality < 50)
item.Quality += 1;
}
private void DecreaseQuality(Item item)
{
if (item.Quality > 0)
item.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
{
Items[i].Quality = Items[i].Quality - Items[i].Quality;
}
}
else
{
if (Items[i].Quality < 50)
{
Items[i].Quality = Items[i].Quality + 1;
}
}
}
}
}
}
} }