From c262bbb922cf68e485c7177879a289a85d66522c Mon Sep 17 00:00:00 2001 From: ieZaky Date: Sun, 31 Oct 2021 11:29:33 +0200 Subject: [PATCH] Added new changes regarding Conjured items and refactored some code structure --- csharp/GildedRose.cs | 89 ++++++++++++++++++------------------------ csharp/Program.cs | 2 +- csharp/csharp.csproj | 28 +++++++++---- csharp/packages.config | 4 +- 4 files changed, 63 insertions(+), 60 deletions(-) diff --git a/csharp/GildedRose.cs b/csharp/GildedRose.cs index c60d97a0..0d29d659 100644 --- a/csharp/GildedRose.cs +++ b/csharp/GildedRose.cs @@ -1,10 +1,16 @@ -using System.Collections.Generic; +using System.Collections; +using System.Collections.Generic; namespace csharp { public class GildedRose { IList Items; + public const int sulfurasMaxQuality = 80; + public const int itemMaxQuality = 50; + public const int qualityScore = 50; + public const int daysToDoublePassesQuantity = 11; + public const int daysToTriplePassesQuantity = 6; public GildedRose(IList Items) { this.Items = Items; @@ -14,73 +20,56 @@ namespace csharp { for (var i = 0; i < Items.Count; i++) { - if (Items[i].Name != "Aged Brie" && Items[i].Name != "Backstage passes to a TAFKAL80ETC concert") + // Updating Quality of items + + if(Items[i].Name == "Aged Brie" && Items[i].Quality < itemMaxQuality) { - if (Items[i].Quality > 0) - { - if (Items[i].Name != "Sulfuras, Hand of Ragnaros") - { - Items[i].Quality = Items[i].Quality - 1; - } - } + Items[i].Quality = Items[i].Quality + 1; } - else + else if(Items[i].Name == "Backstage passes to a TAFKAL80ETC concert" && Items[i].Quality < itemMaxQuality) { - if (Items[i].Quality < 50) + + if (Items[i].SellIn < daysToTriplePassesQuantity) + { + Items[i].Quality = Items[i].Quality + 2; + } + + else if (Items[i].SellIn < daysToDoublePassesQuantity) { 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; - } - } - } } + + } + else if(Items[i].Name == "Conjured Mana Cake" && Items[i].Quality > 0) + { + Items[i].Quality = Items[i].Quality - 2; + } + else if (Items[i].Quality > 0 && Items[i].Name != "Sulfuras, Hand of Ragnaros") + { + Items[i].Quality = Items[i].Quality - 1; } + + // Selling Date if (Items[i].Name != "Sulfuras, Hand of Ragnaros") { Items[i].SellIn = Items[i].SellIn - 1; } + // Selling Date has passed if (Items[i].SellIn < 0) { - if (Items[i].Name != "Aged Brie") + if(Items[i].Name == "Backstage passes to a TAFKAL80ETC concert") { - 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 + Items[i].Quality = 0; + } + else if (Items[i].Name == "Aged Brie" && Items[i].Quality < itemMaxQuality) { - if (Items[i].Quality < 50) - { Items[i].Quality = Items[i].Quality + 1; - } + } + else if(Items[i].Quality > 0 && Items[i].Name != "Sulfuras, Hand of Ragnaros") + { + Items[i].Quality = Items[i].Quality - 1; } } } diff --git a/csharp/Program.cs b/csharp/Program.cs index 36313e27..bcf3bf2f 100644 --- a/csharp/Program.cs +++ b/csharp/Program.cs @@ -9,7 +9,7 @@ namespace csharp { Console.WriteLine("OMGHAI!"); - IList Items = new List{ + List Items = new List{ new Item {Name = "+5 Dexterity Vest", SellIn = 10, Quality = 20}, new Item {Name = "Aged Brie", SellIn = 2, Quality = 0}, new Item {Name = "Elixir of the Mongoose", SellIn = 5, Quality = 7}, diff --git a/csharp/csharp.csproj b/csharp/csharp.csproj index 58213647..95d10cf1 100644 --- a/csharp/csharp.csproj +++ b/csharp/csharp.csproj @@ -1,6 +1,7 @@  - + + Debug @@ -38,21 +39,33 @@ packages\ApprovalTests.3.0.13\lib\net40\ApprovalTests.dll - True packages\ApprovalUtilities.3.0.13\lib\net45\ApprovalUtilities.dll - True packages\ApprovalUtilities.3.0.13\lib\net45\ApprovalUtilities.Net45.dll - True - - packages\NUnit.3.9.0\lib\net45\nunit.framework.dll + + + + + + + + + + C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\Microsoft.VisualC.STLCLR.dll + + + packages\NUnit.3.13.2\lib\net45\nunit.framework.dll + + + + @@ -80,7 +93,8 @@ This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - + +