From d2bf4e2f7e1b43c69af6a950d203be0768cb134e Mon Sep 17 00:00:00 2001 From: OKinane <15254824+OKinane@users.noreply.github.com> Date: Sat, 11 Mar 2023 15:08:31 +0100 Subject: [PATCH] refactoring first pass --- csharpcore/GildedRose/GildedRose.cs | 113 +++++++++++++--------------- 1 file changed, 53 insertions(+), 60 deletions(-) diff --git a/csharpcore/GildedRose/GildedRose.cs b/csharpcore/GildedRose/GildedRose.cs index ed7dc428..b6b7d9a6 100644 --- a/csharpcore/GildedRose/GildedRose.cs +++ b/csharpcore/GildedRose/GildedRose.cs @@ -14,76 +14,69 @@ namespace GildedRoseKata { for (var i = 0; i < Items.Count; i++) { - if (Items[i].Name != "Aged Brie" && Items[i].Name != "Backstage passes to a TAFKAL80ETC concert") + if (Items[i].Name == "Sulfuras, Hand of Ragnaros") { - if (Items[i].Quality > 0) + continue; + } + + Items[i].SellIn = Items[i].SellIn - 1; + + if (Items[i].Name == "Aged Brie") + { + IncreaseQualityByOne(i); + if (Items[i].SellIn < 0) { - if (Items[i].Name != "Sulfuras, Hand of Ragnaros") - { - Items[i].Quality = Items[i].Quality - 1; - } + IncreaseQualityByOne(i); + } + } + else if (Items[i].Name == "Backstage passes to a TAFKAL80ETC concert") + { + IncreaseBackstageQuality(i); + if (Items[i].SellIn < 0) + { + Items[i].Quality = 0; } } else { - if (Items[i].Quality < 50) + DecreaseQualityByOne(i); + if (Items[i].SellIn < 0) { - 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 - { - Items[i].Quality = Items[i].Quality - Items[i].Quality; - } - } - else - { - if (Items[i].Quality < 50) - { - Items[i].Quality = Items[i].Quality + 1; - } + DecreaseQualityByOne(i); } } } } + + private void IncreaseBackstageQuality(int i) + { + IncreaseQualityByOne(i); + + if (Items[i].SellIn < 10) + { + IncreaseQualityByOne(i); + } + + if (Items[i].SellIn < 5) + { + IncreaseQualityByOne(i); + } + } + + private void DecreaseQualityByOne(int i) + { + if (Items[i].Quality > 0) + { + Items[i].Quality = Items[i].Quality - 1; + } + } + + private void IncreaseQualityByOne(int i) + { + if (Items[i].Quality < 50) + { + Items[i].Quality = Items[i].Quality + 1; + } + } } }