Created
December 1, 2014 22:36
-
-
Save AndyStewart/d564af7dda9a7432bdd4 to your computer and use it in GitHub Desktop.
Gilded Rose
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace gildedrose | |
{ | |
public class GildedRose | |
{ | |
// private static List<Item> items = null; | |
// | |
// public static void main(String[] args) { | |
// System.out.println("OMGHAI!"); | |
// items = new ArrayList<Item>(); | |
// items.add(new Item("+5 Dexterity Vest", 10, 20)); | |
// items.add(new Item("Aged Brie", 2, 0)); | |
// items.add(new Item("Elixir of the Mongoose", 5, 7)); | |
// items.add(new Item("Sulfuras, Hand of Ragnaros", 0, 80)); | |
// items.add(new Item("Backstage passes to a TAFKAL80ETC concert", 15, 20)); | |
// items.add(new Item("Conjured Mana Cake", 3, 6)); | |
// updateQuality(items); | |
// } | |
public static void updateQuality(List<Item> items) | |
{ | |
foreach (var currentItem in items) { | |
currentItem.Update(); | |
} | |
} | |
} | |
public interface IUpdateQuality | |
{ | |
void Update(); | |
} | |
public class Sulfuras : Item | |
{ | |
public Sulfuras (int sellIn, int quality) : base("Sulfuras, Hand of Ragnaros", sellIn, quality) | |
{ | |
} | |
public override void Update() | |
{ | |
} | |
} | |
public class ConjuredItem : Item | |
{ | |
public ConjuredItem (int sellIn, int quality) : base("Conjured Mana Cake", sellIn, quality) | |
{ | |
} | |
public override void Update() | |
{ | |
if (IsQuality) { | |
DecreaseQuality(); | |
} | |
sellIn--; | |
if (sellIn < 0 && IsQuality) { | |
DecreaseQuality(); | |
} | |
} | |
} | |
public class BackStagePass : Item | |
{ | |
public BackStagePass (int sellIn, int quality) : base("Backstage passes to a TAFKAL80ETC concert", sellIn, quality) | |
{ | |
} | |
public override void Update() | |
{ | |
if (quality < 50) { | |
IncreaseQuality(); | |
if (sellIn < 11) { | |
IncreaseQuality(); | |
} | |
if (sellIn < 6) { | |
IncreaseQuality(); | |
} | |
} | |
sellIn--; | |
if (sellIn < 0) { | |
ResetQuality(); | |
} | |
} | |
} | |
public class AgedBrie : Item | |
{ | |
public AgedBrie (int sellIn, int quality) : base("Aged Brie", sellIn, quality) | |
{ | |
} | |
public override void Update() | |
{ | |
if (quality < 50) { | |
IncreaseQuality(); | |
} | |
sellIn --; | |
if (sellIn < 0 && quality < 50) { | |
IncreaseQuality(); | |
} | |
} | |
} | |
public class Item : IUpdateQuality { | |
public String name; | |
public int sellIn; | |
public int quality; | |
public Item(String name, int sellIn, int quality) { | |
this.name = name; | |
this.sellIn = sellIn; | |
this.quality = quality; | |
} | |
public virtual void Update() | |
{ | |
if (IsQuality) { | |
DecreaseQuality(); | |
} | |
sellIn --; | |
if (sellIn < 0) { | |
if (IsQuality) { | |
DecreaseQuality(); | |
} | |
} | |
} | |
public bool IsQuality | |
{ | |
get | |
{ | |
return quality > 0; | |
} | |
} | |
public void ResetQuality() | |
{ | |
quality = (quality - quality); | |
} | |
public void DecreaseQuality() | |
{ | |
quality = quality - 1; | |
} | |
public void IncreaseQuality() | |
{ | |
quality = quality + 1; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment