From ad8263292a0521f2371533ff51947a9066bbc078 Mon Sep 17 00:00:00 2001 From: Voldart <74236937+bohdandash@users.noreply.github.com> Date: Sun, 23 Apr 2023 16:04:48 +0300 Subject: [PATCH] Update --- csharp/GildedRose.cs | 129 ++++++++++++++++++++----------------------- 1 file changed, 59 insertions(+), 70 deletions(-) diff --git a/csharp/GildedRose.cs b/csharp/GildedRose.cs index c60d97a0..dda83ab1 100644 --- a/csharp/GildedRose.cs +++ b/csharp/GildedRose.cs @@ -2,88 +2,77 @@ namespace csharp { - public class GildedRose + namespace csharp { - IList Items; - public GildedRose(IList Items) + public class GildedRose { - this.Items = Items; - } - - public void UpdateQuality() - { - for (var i = 0; i < Items.Count; i++) + IList Items; + public GildedRose(IList Items) { - 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) - { - if (Items[i].Name != "Sulfuras, Hand of Ragnaros") - { - Items[i].Quality = Items[i].Quality - 1; - } - } + UpdateItemQuality(item); + UpdateItemSellIn(item); } - else + } + + private void UpdateItemQuality(Item item) + { + if (item.Name == "Sulfuras, Hand of Ragnaros") + return; + + if (item.Name == "Aged Brie") { - 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; - } - } - } - } + IncreaseQuality(item); + if (item.SellIn < 0) + IncreaseQuality(item); + return; } - 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) - { - 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; - } - } - } + 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; } } } + }