gilded-rose-dotnet-core/GildedRose.cs

91 lines
3.0 KiB
C#
Raw Normal View History

2020-08-31 17:32:41 +00:00
using System.Collections.Generic;
namespace csharpcore
{
public class GildedRose
{
2020-08-31 19:38:16 +00:00
private readonly IList<Item> _items;
public GildedRose(IList<Item> items)
2020-08-31 17:32:41 +00:00
{
2020-08-31 19:38:16 +00:00
_items = items;
2020-08-31 17:32:41 +00:00
}
public void UpdateQuality()
{
2020-08-31 19:38:16 +00:00
for (var i = 0; i < _items.Count; i++)
2020-08-31 17:32:41 +00:00
{
2020-08-31 19:38:16 +00:00
if (_items[i].Name != "Aged Brie" && _items[i].Name != "Backstage passes to a TAFKAL80ETC concert")
2020-08-31 17:32:41 +00:00
{
2020-08-31 19:38:16 +00:00
if (_items[i].Quality > 0)
2020-08-31 17:32:41 +00:00
{
2020-08-31 19:38:16 +00:00
if (_items[i].Name != "Sulfuras, Hand of Ragnaros")
2020-08-31 17:32:41 +00:00
{
2020-08-31 19:38:16 +00:00
_items[i].Quality = _items[i].Quality - 1;
2020-08-31 17:32:41 +00:00
}
}
}
else
{
2020-08-31 19:38:16 +00:00
if (_items[i].Quality < 50)
2020-08-31 17:32:41 +00:00
{
2020-08-31 19:38:16 +00:00
_items[i].Quality = _items[i].Quality + 1;
2020-08-31 17:32:41 +00:00
2020-08-31 19:38:16 +00:00
if (_items[i].Name == "Backstage passes to a TAFKAL80ETC concert")
2020-08-31 17:32:41 +00:00
{
2020-08-31 19:38:16 +00:00
if (_items[i].SellIn < 11)
2020-08-31 17:32:41 +00:00
{
2020-08-31 19:38:16 +00:00
if (_items[i].Quality < 50)
2020-08-31 17:32:41 +00:00
{
2020-08-31 19:38:16 +00:00
_items[i].Quality = _items[i].Quality + 1;
2020-08-31 17:32:41 +00:00
}
}
2020-08-31 19:38:16 +00:00
if (_items[i].SellIn < 6)
2020-08-31 17:32:41 +00:00
{
2020-08-31 19:38:16 +00:00
if (_items[i].Quality < 50)
2020-08-31 17:32:41 +00:00
{
2020-08-31 19:38:16 +00:00
_items[i].Quality = _items[i].Quality + 1;
2020-08-31 17:32:41 +00:00
}
}
}
}
}
2020-08-31 19:38:16 +00:00
if (_items[i].Name != "Sulfuras, Hand of Ragnaros")
2020-08-31 17:32:41 +00:00
{
2020-08-31 19:38:16 +00:00
_items[i].SellIn = _items[i].SellIn - 1;
2020-08-31 17:32:41 +00:00
}
2020-08-31 19:38:16 +00:00
if (_items[i].SellIn < 0)
2020-08-31 17:32:41 +00:00
{
2020-08-31 19:38:16 +00:00
if (_items[i].Name != "Aged Brie")
2020-08-31 17:32:41 +00:00
{
2020-08-31 19:38:16 +00:00
if (_items[i].Name != "Backstage passes to a TAFKAL80ETC concert")
2020-08-31 17:32:41 +00:00
{
2020-08-31 19:38:16 +00:00
if (_items[i].Quality > 0)
2020-08-31 17:32:41 +00:00
{
2020-08-31 19:38:16 +00:00
if (_items[i].Name != "Sulfuras, Hand of Ragnaros")
2020-08-31 17:32:41 +00:00
{
2020-08-31 19:38:16 +00:00
_items[i].Quality = _items[i].Quality - 1;
2020-08-31 17:32:41 +00:00
}
}
}
else
{
2020-08-31 19:38:16 +00:00
_items[i].Quality = _items[i].Quality - _items[i].Quality;
2020-08-31 17:32:41 +00:00
}
}
else
{
2020-08-31 19:38:16 +00:00
if (_items[i].Quality < 50)
2020-08-31 17:32:41 +00:00
{
2020-08-31 19:38:16 +00:00
_items[i].Quality = _items[i].Quality + 1;
2020-08-31 17:32:41 +00:00
}
}
}
}
}
}
}