mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-19 08:21:37 +00:00
update
Just thought I simplify some parts to use less code.
This commit is contained in:
parent
e47d9f3392
commit
d963d7c29c
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
|
|
||||||
namespace csharp
|
namespace csharp
|
||||||
{
|
{
|
||||||
|
#region Interface
|
||||||
interface IUpdateInterface
|
interface IUpdateInterface
|
||||||
{
|
{
|
||||||
void CalculateItemQuality(Item item, int decrementValue, int incrementValue); //takes 3 self explanatory params.
|
void CalculateItemQuality(Item item, int decrementValue, int incrementValue); //takes 3 self explanatory params.
|
||||||
@ -10,15 +11,19 @@ namespace csharp
|
|||||||
void MinMaxRules(Item item); // Minimum and Maximum Rules for item quality
|
void MinMaxRules(Item item); // Minimum and Maximum Rules for item quality
|
||||||
void ReduceSellIn(Item item); // Reduce number of days left method
|
void ReduceSellIn(Item item); // Reduce number of days left method
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
public class GildedRose : IUpdateInterface
|
public class GildedRose : IUpdateInterface
|
||||||
{
|
{
|
||||||
IList<Item> Items;
|
#region constructor
|
||||||
|
private IList<Item> Items;
|
||||||
public GildedRose(IList<Item> Items)
|
public GildedRose(IList<Item> Items)
|
||||||
{
|
{
|
||||||
this.Items = Items;
|
this.Items = Items;
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Update Quality
|
||||||
public void UpdateQuality()
|
public void UpdateQuality()
|
||||||
{
|
{
|
||||||
foreach (var Item in Items) // Changed this to a simpler loop
|
foreach (var Item in Items) // Changed this to a simpler loop
|
||||||
@ -30,8 +35,7 @@ namespace csharp
|
|||||||
CalculateSpecialItemQuality(Item);
|
CalculateSpecialItemQuality(Item);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
CalculateLegendaryItemQuality
|
CalculateLegendaryItemQuality(Item);
|
||||||
(Item, 0, 0);
|
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
CalculateItemQuality(Item, 4, 0);
|
CalculateItemQuality(Item, 4, 0);
|
||||||
@ -40,88 +44,54 @@ namespace csharp
|
|||||||
CalculateItemQuality(Item, 2, 0);
|
CalculateItemQuality(Item, 2, 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
//if (Item.Name == "Aged Brie")
|
|
||||||
//{
|
|
||||||
// CalculateSpecialItemQuality(Item);
|
|
||||||
// //MinMaxRules(Item);
|
|
||||||
// //return;
|
|
||||||
//}
|
|
||||||
//else if (Item.Name == "Sulfuras, Hand of Ragnaros")
|
|
||||||
//{
|
|
||||||
// //CalculateQuality(Item, 0, 0);
|
|
||||||
// //return;
|
|
||||||
//}
|
|
||||||
//else if (Item.Name == "Conjured Mana Cake")
|
|
||||||
//{
|
|
||||||
// CalculateStandardItemQuality(Item, 4, 0);
|
|
||||||
// //return;
|
|
||||||
//}
|
|
||||||
//else
|
|
||||||
//{
|
|
||||||
// CalculateStandardItemQuality(Item, 2, 0);
|
|
||||||
// //return;
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Calculate Item Quality
|
||||||
public void CalculateItemQuality(Item item, int decrementValue, int IncrementValue) // To calculate the quality of each item
|
public void CalculateItemQuality(Item item, int decrementValue, int IncrementValue) // To calculate the quality of each item
|
||||||
{
|
{
|
||||||
//if (item.SellIn > 0 )
|
item.Quality -= decrementValue;
|
||||||
{
|
|
||||||
item.Quality = item.Quality - decrementValue;
|
|
||||||
}
|
|
||||||
MinMaxRules(item);
|
MinMaxRules(item);
|
||||||
ReduceSellIn(item);
|
ReduceSellIn(item);
|
||||||
}
|
}
|
||||||
public void CalculateLegendaryItemQuality(Item item, int decrementValue, int IncrementValue) // To calculate the quality of each item
|
#endregion
|
||||||
|
|
||||||
|
#region Calculate LEgendary Item Quality
|
||||||
|
public void CalculateLegendaryItemQuality(Item item) // To calculate the quality of each item
|
||||||
{
|
{
|
||||||
////if (item.SellIn > 0 )
|
|
||||||
//{
|
|
||||||
// item.Quality = item.Quality - decrementValue;
|
|
||||||
//}
|
|
||||||
//MinMaxRules(item);
|
|
||||||
ReduceSellIn(item);
|
ReduceSellIn(item);
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Calculate Special Item Quality
|
||||||
public void CalculateSpecialItemQuality(Item item) // Specific for the AgedBrie Special Item
|
public void CalculateSpecialItemQuality(Item item) // Specific for the AgedBrie Special Item
|
||||||
{
|
{
|
||||||
if (item.SellIn == 0)
|
item.Quality = item.SellIn == 0 ? 0 : item.Quality;
|
||||||
{
|
item.Quality = (item.SellIn <= 10 && item.SellIn > 5 && item.SellIn > 0) ? item.Quality + 2 : item.Quality;
|
||||||
item.Quality = 0;
|
item.Quality = (item.SellIn <= 5 && item.SellIn > 0) ? item.Quality + 3 : item.Quality;
|
||||||
}
|
|
||||||
|
|
||||||
if (item.SellIn <= 10 && item.SellIn > 5 && item.SellIn > 0)
|
|
||||||
{
|
|
||||||
item.Quality = item.Quality + 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item.SellIn <= 5 && item.SellIn > 0)
|
|
||||||
{
|
|
||||||
item.Quality = item.Quality + 3;
|
|
||||||
}
|
|
||||||
ReduceSellIn(item);
|
ReduceSellIn(item);
|
||||||
MinMaxRules(item);
|
MinMaxRules(item);
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Minimum and Maximum Rules
|
||||||
public void MinMaxRules(Item item) //Minimum and Maximum Rules
|
public void MinMaxRules(Item item) //Minimum and Maximum Rules
|
||||||
{
|
{
|
||||||
if (item.Quality <= 0)
|
item.Quality = (item.Quality <= 0) ? 0 : item.Quality;
|
||||||
{
|
item.Quality = (item.Quality >= 50) ? 50 : item.Quality;
|
||||||
item.Quality = 0;
|
|
||||||
}
|
|
||||||
if (item.Quality >= 50)
|
|
||||||
{
|
|
||||||
item.Quality = 50;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Reduce Sell In
|
||||||
public void ReduceSellIn(Item item) //This will take care of reducing the number of days after each day
|
public void ReduceSellIn(Item item) //This will take care of reducing the number of days after each day
|
||||||
{
|
{
|
||||||
//if (item.SellIn >= 1)
|
item.SellIn -= 1;
|
||||||
{
|
|
||||||
item.SellIn = item.SellIn - 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Categorize Items
|
||||||
// Here is an attempt to categorize the items since am not allowed to touch the items class
|
// Here is an attempt to categorize the items since am not allowed to touch the items class
|
||||||
public int Categorize(String itemName) //This will take care of reducing the number of days after each day
|
public int Categorize(String itemName) //This will take care of reducing the number of days after each day
|
||||||
{
|
{
|
||||||
@ -143,6 +113,6 @@ namespace csharp
|
|||||||
}
|
}
|
||||||
return categoryID;
|
return categoryID;
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,10 +1,5 @@
|
|||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
using csharp;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace csharp.Tests
|
namespace csharp.Tests
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user