diff --git a/csharp/App.config b/csharp/App.config index 88fa4027..4bfa0056 100644 --- a/csharp/App.config +++ b/csharp/App.config @@ -1,6 +1,6 @@ - + - + - \ No newline at end of file + diff --git a/csharp/GildedRose.cs b/csharp/GildedRose.cs index c60d97a0..ac9c4192 100644 --- a/csharp/GildedRose.cs +++ b/csharp/GildedRose.cs @@ -1,5 +1,5 @@ using System.Collections.Generic; - +using System; namespace csharp { public class GildedRose @@ -9,79 +9,92 @@ namespace csharp { this.Items = Items; } - - public void UpdateQuality() + void UpdateItem(ref Item item, int sellInValueFactor, int qualityValueFactor) { - for (var i = 0; i < Items.Count; i++) + item.SellIn += sellInValueFactor; + item.Quality = Math.Max(0, Math.Min(50, item.Quality + qualityValueFactor)); + + } + bool IsExpired(Item item) + { + bool output = true; + if (item.SellIn > 0) + output = false; + return output; + } + Item GetNewAgedBrie(Item item) + { + if (IsExpired(item)) + UpdateItem(ref item, -1, 2); + else + UpdateItem(ref item, -1, 1); + return item; + } + Item GetNewBackstagesPasses(Item item) + { + if (IsExpired(item)) + item.Quality = 0; + else { - if (Items[i].Name != "Aged Brie" && Items[i].Name != "Backstage passes to a TAFKAL80ETC concert") + if (item.SellIn <= 10 && item.SellIn > 5) { - if (Items[i].Quality > 0) - { - if (Items[i].Name != "Sulfuras, Hand of Ragnaros") - { - Items[i].Quality = Items[i].Quality - 1; - } - } + UpdateItem(ref item, -1, 2); + } + else if (item.SellIn <= 5) + { + UpdateItem(ref item, -1, 3); } 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) - { - if (Items[i].Quality < 50) - { - Items[i].Quality = Items[i].Quality + 1; - } - } - } - } + UpdateItem(ref item, -1, 1); } - - if (Items[i].Name != "Sulfuras, Hand of Ragnaros") + } + return item; + } + Item GetNewConjured(Item item) + { + if (IsExpired(item)) + { + UpdateItem(ref item, -1, -4); + } + else + { + UpdateItem(ref item, -1, -2); + } + return item; + } + Item GetNewDefault(Item item) + { + if (IsExpired(item)) + { + UpdateItem(ref item, -1, -2); + } + else + { + UpdateItem(ref item, -1, -1); + } + return item; + } + public void UpdateQuality() + { + for (int itemIndex = 0; itemIndex < Items.Count; itemIndex++) + { + switch (Items[itemIndex].Name) { - 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; - } - } + case "Aged Brie": + Items[itemIndex] = GetNewAgedBrie(Items[itemIndex]); + break; + case "Sulfuras, Hand of Ragnaros": + break; + case "Backstage passes to a TAFKAL80ETC concert": + Items[itemIndex] = GetNewBackstagesPasses(Items[itemIndex]); + break; + case "Conjured Mana Cake": + Items[itemIndex] = GetNewConjured(Items[itemIndex]); + break; + default: + Items[itemIndex] = GetNewDefault(Items[itemIndex]); + break; } } } diff --git a/csharp/csharp.csproj b/csharp/csharp.csproj index 58213647..85e0f51b 100644 --- a/csharp/csharp.csproj +++ b/csharp/csharp.csproj @@ -10,11 +10,12 @@ Properties csharp csharp - v4.5.2 + v4.8 512 true + AnyCPU