Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,4 @@ $RECYCLE.BIN/
*.msi
*.msm
*.msp
/.vs
Expand Down
4 changes: 2 additions & 2 deletions GildedRose.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.31101.0
# Visual Studio Version 17
VisualStudioVersion = 17.10.35004.147
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GildedRose.Tests", "src\GildedRose.Tests\GildedRose.Tests.csproj", "{CD4715A2-532E-4C74-BC40-36EE64F61FCA}"
EndProject
Expand Down
6 changes: 6 additions & 0 deletions src/GildedRose.Console/GildedRose.Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,14 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Items\AgedBrieItem.cs" />
<Compile Include="Items\BackstageItem.cs" />
<Compile Include="Inn.cs" />
<Compile Include="Items\ConjuredItem.cs" />
<Compile Include="Items\Item.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Items\SulfurasItem.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
Expand Down
22 changes: 22 additions & 0 deletions src/GildedRose.Console/Inn.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Collections.Generic;

namespace GildedRose.Console
{
internal class Inn
{
public IReadOnlyList<Item> Items { get; }

public Inn(IList<Item> items)
{
this.Items = ((List<Item>)items).AsReadOnly();
}

public void UpdateItem()
{
for (var i = 0; i < Items.Count; i++)
{
Items[i].Update();
}
}
}
}
32 changes: 32 additions & 0 deletions src/GildedRose.Console/Items/AgedBrieItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
namespace GildedRose.Console
{
public class AgedBrieItem : Item
{
public AgedBrieItem(int sellIn, int quality) : base()
{
this.Name = "Aged Brie";
this.SellIn = sellIn;
this.Quality = quality;
}

public override void Update()
{
this.UpdateQuality();

this.DecreaseSellIn();

if (this.SellIn < 0)
{
this.UpdateQuality();
}
}

protected override void UpdateQuality()
{
if (this.Quality < 50)
{
this.Quality++;
}
}
}
}
42 changes: 42 additions & 0 deletions src/GildedRose.Console/Items/BackstageItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
namespace GildedRose.Console
{
public class BackstageItem : Item
{
public BackstageItem(int sellIn, int quality) : base()
{
this.Name = "Backstage passes to a TAFKAL80ETC concert";
this.SellIn = sellIn;
this.Quality = quality;
}

public override void Update()
{
this.UpdateQuality();

if (this.SellIn < 11)
{
this.UpdateQuality();
}

if (this.SellIn < 6)
{
this.UpdateQuality();
}

this.DecreaseSellIn();

if (this.SellIn < 0)
{
this.Quality = this.Quality - this.Quality;
}
}

protected override void UpdateQuality()
{
if (this.Quality < 50)
{
this.Quality++;
}
}
}
}
19 changes: 19 additions & 0 deletions src/GildedRose.Console/Items/ConjuredItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace GildedRose.Console
{
public class ConjuredItem : Item
{
public ConjuredItem(int sellIn, int quality) : base()
{
this.Name = "Conjured Mana Cake";
this.SellIn = sellIn;
this.Quality = quality;
}

public override void Update()
{
this.UpdateQuality();
this.UpdateQuality();
this.DecreaseSellIn();
}
}
}
36 changes: 36 additions & 0 deletions src/GildedRose.Console/Items/Item.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
namespace GildedRose.Console
{
public class Item
{
public string Name { get; set; }

public int SellIn { get; set; }

public int Quality { get; set; }

public virtual void Update()
{
this.UpdateQuality();

this.DecreaseSellIn();

if (this.SellIn < 0)
{
this.UpdateQuality();
}
}

protected virtual void UpdateQuality()
{
if (this.Quality > 0)
{
this.Quality = this.Quality - 1;
}
}

protected void DecreaseSellIn()
{
this.SellIn = this.SellIn - 1;
}
}
}
17 changes: 17 additions & 0 deletions src/GildedRose.Console/Items/SulfurasItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace GildedRose.Console
{
public class SulfurasItem : Item
{
public SulfurasItem(int sellIn, int quality) : base()
{
this.Name = "Sulfuras, Hand of Ragnaros";
this.SellIn = sellIn;
this.Quality = quality;
}

public override void Update()
{
// Sulfuras never has to be sold or decreases in Quality
}
}
}
101 changes: 8 additions & 93 deletions src/GildedRose.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

namespace GildedRose.Console
{
class Program
public class Program
{
IList<Item> Items;
public IList<Item> Items;

static void Main(string[] args)
{
System.Console.WriteLine("OMGHAI!");
Expand All @@ -14,16 +15,11 @@ static void Main(string[] args)
Items = new List<Item>
{
new Item {Name = "+5 Dexterity Vest", SellIn = 10, Quality = 20},
new Item {Name = "Aged Brie", SellIn = 2, Quality = 0},
new AgedBrieItem(sellIn: 2, quality: 0),
new Item {Name = "Elixir of the Mongoose", SellIn = 5, Quality = 7},
new Item {Name = "Sulfuras, Hand of Ragnaros", SellIn = 0, Quality = 80},
new Item
{
Name = "Backstage passes to a TAFKAL80ETC concert",
SellIn = 15,
Quality = 20
},
new Item {Name = "Conjured Mana Cake", SellIn = 3, Quality = 6}
new SulfurasItem(sellIn: 0, quality: 80),
new BackstageItem(sellIn: 15, quality: 20),
new ConjuredItem(sellIn: 3, quality: 6)
}

};
Expand All @@ -36,89 +32,8 @@ static void Main(string[] args)

public void UpdateQuality()
{
for (var i = 0; i < Items.Count; i++)
{
if (Items[i].Name != "Aged Brie" && 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
{
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;
}
}
}
}
}

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;
}
}
}
}
new Inn(this.Items).UpdateItem();
}

}

public class Item
{
public string Name { get; set; }

public int SellIn { get; set; }

public int Quality { get; set; }
}

}
6 changes: 6 additions & 0 deletions src/GildedRose.Tests/GildedRose.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\GildedRose.Console\GildedRose.Console.csproj">
<Project>{F2E879A9-7F1C-4C34-AB0D-2662F9815046}</Project>
<Name>GildedRose.Console</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
Expand Down
Loading