mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 14:31:28 +00:00
New UpdateQuality method, now works with conjured items
This commit is contained in:
parent
5a4e92199b
commit
495b289649
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
|
||||
</startup>
|
||||
</configuration>
|
||||
</configuration>
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System;
|
||||
namespace csharp
|
||||
{
|
||||
public class GildedRose
|
||||
@ -9,81 +9,95 @@ 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,11 +10,12 @@
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>csharp</RootNamespace>
|
||||
<AssemblyName>csharp</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<NuGetPackageImportStamp>
|
||||
</NuGetPackageImportStamp>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user