Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions csharp/BetterWithAgeUpdateableItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace csharp
{
internal class BetterWithAgeUpdateableItem : UpdateableItem
{
public override void UpdateQualityItem()
{

SellIn--;
if (this.Quality >= 50) return;
if (this.SellIn < 0)
{
this.Quality++;
}
this.Quality++;
if (Quality > 0)
{
Quality = 50;
}
}
}
}
17 changes: 17 additions & 0 deletions csharp/CannedUpdatedableItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace csharp
{
internal class CannedUpdatedableItem : UpdateableItem
{
public override void UpdateQualityItem()
{
this.Quality = 80;
return;
}
}
}
33 changes: 33 additions & 0 deletions csharp/DoubleDegradeItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace csharp
{
internal class DoubleDegradeItem : UpdateableItem
{
public override void UpdateQualityItem()
{
this.SellIn--;

if (Quality > 0)
{
if (SellIn < 0)
{
Quality -= 4;
}
else
{
Quality -= 2;
}

if (Quality < 0)
{
Quality = 0;
}
}
}
}
}
41 changes: 41 additions & 0 deletions csharp/FoodFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Text;
using System.Threading.Tasks;

namespace csharp
{
internal class FoodItemFactory
{

public static UpdateableItem Create(Foods foodType, string itemName, int sellin, int quality)
{
UpdateableItem item;
if (foodType == Foods.AgedBrie)
{
item = new BetterWithAgeUpdateableItem();
}
else if (foodType == Foods.CannedBeans)
{
item = new CannedUpdatedableItem();

}
else if (foodType == Foods.DoubleDegradeItem)
{
item = new DoubleDegradeItem();
}
else
{
item = new GenericUpdatableItem();
}

item.Name = itemName;
item.Quality = quality;
item.SellIn = sellin;
return item;

}
}
}
17 changes: 17 additions & 0 deletions csharp/Foods.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace csharp
{
internal enum Foods
{
CannedBeans,
AgedBrie,
GenericItem,
DoubleDegradeItem

}
}
21 changes: 21 additions & 0 deletions csharp/GenericUpdatableItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace csharp
{
internal class GenericUpdatableItem : UpdateableItem
{
public override void UpdateQualityItem()
{

SellIn--;
if (SellIn < 0 && this.Quality > 0)
{
this.Quality--;
}
}
}
}
50 changes: 4 additions & 46 deletions csharp/GildedRose.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,59 +4,17 @@ namespace csharp
{
public class GildedRose
{
IList<Item> Items;
public GildedRose(IList<Item> Items)
IList<UpdateableItem> Items;
public GildedRose(IList<UpdateableItem> Items)
{
this.Items = Items;
}

public void UpdateQuality()
{
for (var i = 0; i < Items.Count; i++)
foreach (UpdateableItem item in Items)
{
if (Items[i].Name != "Canned Beans")
{
Items[i].SellIn = Items[i].SellIn - 1;
}

if (Items[i].Name == "Aged Brie")
{
if (Items[i].Quality < 50)
{
Items[i].Quality = Items[i].Quality + 1;
}
}
else
{
if (Items[i].Quality > 0)
{
if (Items[i].Name != "Canned Beans")
{
Items[i].Quality = Items[i].Quality - 1;
}
}
}

if (Items[i].SellIn < 0)
{
if (Items[i].Name == "Aged Brie")
{
if (Items[i].Quality < 50)
{
Items[i].Quality = Items[i].Quality + 1;
}
}
else
{
if (Items[i].Quality > 0)
{
if (Items[i].Name != "Canned Beans")
{
Items[i].Quality = Items[i].Quality - 1;
}
}
}
}
item.UpdateQualityItem();
}
}
}
Expand Down
15 changes: 15 additions & 0 deletions csharp/IUpdateable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace csharp
{
public abstract class UpdateableItem : Item
{

public abstract void UpdateQualityItem();

}
}
24 changes: 14 additions & 10 deletions csharp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@ public class Program

public static void Main(string[] args)
{
IList<Item> Items = new List<Item>{
new Item {Name = "Bananas", SellIn = 10, Quality = 20},
new Item {Name = "Aged Brie", SellIn = 2, Quality = 0},
new Item {Name = "Eggs", SellIn = 5, Quality = 7},
new Item {Name = "Eggs", SellIn = 12, Quality = 5},
new Item {Name = "Canned Beans", SellIn = 0, Quality = 80},
new Item {Name = "Canned Beans", SellIn = -1, Quality = 80},

// This Baked good does not work properly yet!
new Item {Name = "Baked Sourdough Bread", SellIn = 3, Quality = 6}
var Items = new List<UpdateableItem>
{

FoodItemFactory.Create(Foods.GenericItem, "Bananas", 10, 20),
FoodItemFactory.Create(Foods.AgedBrie, "Aged Brie", 2, 0),

FoodItemFactory.Create(Foods.GenericItem, "Eggs", 5, 7),
FoodItemFactory.Create(Foods.GenericItem, "Eggs", 12, 5),

FoodItemFactory.Create(Foods.CannedBeans, "Canned Beans", 0, 80),
FoodItemFactory.Create(Foods.CannedBeans, "Canned Beans", -1, 80),
FoodItemFactory.Create(Foods.DoubleDegradeItem, "Baked Sourdough Bread", 3, 6)
};

var app = new GildedRose(Items);
Expand All @@ -35,6 +37,8 @@ public static void Main(string[] args)
Console.WriteLine("");
app.UpdateQuality();
}

Console.ReadKey();
}
}
}
7 changes: 7 additions & 0 deletions csharp/csharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,15 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="BetterWithAgeUpdateableItem.cs" />
<Compile Include="CannedUpdatedableItem.cs" />
<Compile Include="DoubleDegradeItem.cs" />
<Compile Include="FoodFactory.cs" />
<Compile Include="Foods.cs" />
<Compile Include="GenericUpdatableItem.cs" />
<Compile Include="GildedRose.cs" />
<Compile Include="Item.cs" />
<Compile Include="IUpdateable.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand Down