New UpdateQuality method, now works with Conjured items

This commit is contained in:
Greden Night 2023-04-23 16:20:09 +03:00
parent 5a4e92199b
commit 634f8e5ad0
3 changed files with 84 additions and 70 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8"?>
<configuration> <configuration>
<startup> <startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
</startup> </startup>
</configuration> </configuration>

View File

@ -1,5 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using System;
namespace csharp namespace csharp
{ {
public class GildedRose public class GildedRose
@ -9,79 +9,92 @@ namespace csharp
{ {
this.Items = Items; this.Items = Items;
} }
void UpdateItem(ref Item item, int sellInValueFactor, int qualityValueFactor)
{
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 (item.SellIn <= 10 && item.SellIn > 5)
{
UpdateItem(ref item, -1, 2);
}
else if (item.SellIn <= 5)
{
UpdateItem(ref item, -1, 3);
}
else
{
UpdateItem(ref item, -1, 1);
}
}
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() public void UpdateQuality()
{ {
for (var i = 0; i < Items.Count; i++) for (int itemIndex = 0; itemIndex < Items.Count; itemIndex++)
{ {
if (Items[i].Name != "Aged Brie" && Items[i].Name != "Backstage passes to a TAFKAL80ETC concert") switch (Items[itemIndex].Name)
{ {
if (Items[i].Quality > 0) case "Aged Brie":
{ Items[itemIndex] = GetNewAgedBrie(Items[itemIndex]);
if (Items[i].Name != "Sulfuras, Hand of Ragnaros") break;
{ case "Sulfuras, Hand of Ragnaros":
Items[i].Quality = Items[i].Quality - 1; break;
} case "Backstage passes to a TAFKAL80ETC concert":
} Items[itemIndex] = GetNewBackstagesPasses(Items[itemIndex]);
} break;
else case "Conjured Mana Cake":
{ Items[itemIndex] = GetNewConjured(Items[itemIndex]);
if (Items[i].Quality < 50) break;
{ default:
Items[i].Quality = Items[i].Quality + 1; Items[itemIndex] = GetNewDefault(Items[itemIndex]);
break;
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;
}
}
} }
} }
} }

View File

@ -10,11 +10,12 @@
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>csharp</RootNamespace> <RootNamespace>csharp</RootNamespace>
<AssemblyName>csharp</AssemblyName> <AssemblyName>csharp</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion> <TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<NuGetPackageImportStamp> <NuGetPackageImportStamp>
</NuGetPackageImportStamp> </NuGetPackageImportStamp>
<TargetFrameworkProfile />
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget> <PlatformTarget>AnyCPU</PlatformTarget>