Added new changes regarding Conjured items and refactored some code structure

This commit is contained in:
ieZaky 2021-10-31 11:29:33 +02:00
parent 864f34ccc1
commit c262bbb922
4 changed files with 63 additions and 60 deletions

View File

@ -1,10 +1,16 @@
using System.Collections.Generic; using System.Collections;
using System.Collections.Generic;
namespace csharp namespace csharp
{ {
public class GildedRose public class GildedRose
{ {
IList<Item> Items; IList<Item> 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<Item> Items) public GildedRose(IList<Item> Items)
{ {
this.Items = Items; this.Items = Items;
@ -14,73 +20,56 @@ namespace csharp
{ {
for (var i = 0; i < Items.Count; i++) 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) Items[i].Quality = Items[i].Quality + 1;
{
if (Items[i].Name != "Sulfuras, Hand of Ragnaros")
{
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; 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") if (Items[i].Name != "Sulfuras, Hand of Ragnaros")
{ {
Items[i].SellIn = Items[i].SellIn - 1; Items[i].SellIn = Items[i].SellIn - 1;
} }
// Selling Date has passed
if (Items[i].SellIn < 0) 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") Items[i].Quality = 0;
{ }
if (Items[i].Quality > 0) else if (Items[i].Name == "Aged Brie" && Items[i].Quality < itemMaxQuality)
{
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; 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;
} }
} }
} }

View File

@ -9,7 +9,7 @@ namespace csharp
{ {
Console.WriteLine("OMGHAI!"); Console.WriteLine("OMGHAI!");
IList<Item> Items = new List<Item>{ List<Item> Items = new List<Item>{
new Item {Name = "+5 Dexterity Vest", SellIn = 10, Quality = 20}, new Item {Name = "+5 Dexterity Vest", SellIn = 10, Quality = 20},
new Item {Name = "Aged Brie", SellIn = 2, Quality = 0}, new Item {Name = "Aged Brie", SellIn = 2, Quality = 0},
new Item {Name = "Elixir of the Mongoose", SellIn = 5, Quality = 7}, new Item {Name = "Elixir of the Mongoose", SellIn = 5, Quality = 7},

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="packages\NUnit3TestAdapter.3.9.0\build\net35\NUnit3TestAdapter.props" Condition="Exists('packages\NUnit3TestAdapter.3.9.0\build\net35\NUnit3TestAdapter.props')" /> <Import Project="packages\NUnit3TestAdapter.4.0.0\build\net35\NUnit3TestAdapter.props" Condition="Exists('packages\NUnit3TestAdapter.4.0.0\build\net35\NUnit3TestAdapter.props')" />
<Import Project="packages\NUnit.3.13.2\build\NUnit.props" Condition="Exists('packages\NUnit.3.13.2\build\NUnit.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup> <PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@ -38,21 +39,33 @@
<ItemGroup> <ItemGroup>
<Reference Include="ApprovalTests, Version=3.0.0.0, Culture=neutral, PublicKeyToken=11bd7d124fc62e0f, processorArchitecture=MSIL"> <Reference Include="ApprovalTests, Version=3.0.0.0, Culture=neutral, PublicKeyToken=11bd7d124fc62e0f, processorArchitecture=MSIL">
<HintPath>packages\ApprovalTests.3.0.13\lib\net40\ApprovalTests.dll</HintPath> <HintPath>packages\ApprovalTests.3.0.13\lib\net40\ApprovalTests.dll</HintPath>
<Private>True</Private>
</Reference> </Reference>
<Reference Include="ApprovalUtilities, Version=3.0.0.0, Culture=neutral, PublicKeyToken=11bd7d124fc62e0f, processorArchitecture=MSIL"> <Reference Include="ApprovalUtilities, Version=3.0.0.0, Culture=neutral, PublicKeyToken=11bd7d124fc62e0f, processorArchitecture=MSIL">
<HintPath>packages\ApprovalUtilities.3.0.13\lib\net45\ApprovalUtilities.dll</HintPath> <HintPath>packages\ApprovalUtilities.3.0.13\lib\net45\ApprovalUtilities.dll</HintPath>
<Private>True</Private>
</Reference> </Reference>
<Reference Include="ApprovalUtilities.Net45, Version=3.0.0.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="ApprovalUtilities.Net45, Version=3.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\ApprovalUtilities.3.0.13\lib\net45\ApprovalUtilities.Net45.dll</HintPath> <HintPath>packages\ApprovalUtilities.3.0.13\lib\net45\ApprovalUtilities.Net45.dll</HintPath>
<Private>True</Private>
</Reference> </Reference>
<Reference Include="nunit.framework, Version=3.9.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL"> <Reference Include="ISymWrapper" />
<HintPath>packages\NUnit.3.9.0\lib\net45\nunit.framework.dll</HintPath> <Reference Include="Microsoft.Activities.Build" />
<Reference Include="Microsoft.Build" />
<Reference Include="Microsoft.Build.Conversion.v4.0" />
<Reference Include="Microsoft.Build.Engine" />
<Reference Include="Microsoft.Build.Framework" />
<Reference Include="Microsoft.Build.Tasks.v4.0" />
<Reference Include="Microsoft.Build.Utilities.v4.0" />
<Reference Include="Microsoft.VisualC.STLCLR">
<HintPath>C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\Microsoft.VisualC.STLCLR.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=3.13.2.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>packages\NUnit.3.13.2\lib\net45\nunit.framework.dll</HintPath>
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Data.Entity" />
<Reference Include="System.Data.Entity.Design" />
<Reference Include="System.Data.Linq" />
<Reference Include="System.Data.Services" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" /> <Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" /> <Reference Include="Microsoft.CSharp" />
@ -80,7 +93,8 @@
<PropertyGroup> <PropertyGroup>
<ErrorText>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}.</ErrorText> <ErrorText>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}.</ErrorText>
</PropertyGroup> </PropertyGroup>
<Error Condition="!Exists('packages\NUnit3TestAdapter.3.9.0\build\net35\NUnit3TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', 'packages\NUnit3TestAdapter.3.9.0\build\net35\NUnit3TestAdapter.props'))" /> <Error Condition="!Exists('packages\NUnit.3.13.2\build\NUnit.props')" Text="$([System.String]::Format('$(ErrorText)', 'packages\NUnit.3.13.2\build\NUnit.props'))" />
<Error Condition="!Exists('packages\NUnit3TestAdapter.4.0.0\build\net35\NUnit3TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', 'packages\NUnit3TestAdapter.4.0.0\build\net35\NUnit3TestAdapter.props'))" />
</Target> </Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.

View File

@ -2,6 +2,6 @@
<packages> <packages>
<package id="ApprovalTests" version="3.0.13" targetFramework="net452" /> <package id="ApprovalTests" version="3.0.13" targetFramework="net452" />
<package id="ApprovalUtilities" version="3.0.13" targetFramework="net452" /> <package id="ApprovalUtilities" version="3.0.13" targetFramework="net452" />
<package id="NUnit" version="3.9.0" targetFramework="net452" /> <package id="NUnit" version="3.13.2" targetFramework="net452" />
<package id="NUnit3TestAdapter" version="3.9.0" targetFramework="net452" /> <package id="NUnit3TestAdapter" version="4.0.0" targetFramework="net452" />
</packages> </packages>