-
Notifications
You must be signed in to change notification settings - Fork 0
/
GildedRose.cs
94 lines (81 loc) · 2.56 KB
/
GildedRose.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using System;
using System.Collections.Generic;
using System.Linq;
namespace csharp
{
public class GildedRose
{
private const int minSellIn = 0;
private const int minItemQuality = 0;
private const int maxItemQuality = 50;
private const string agedBrie = "Aged Brie";
private const string concertTickets = "Backstage passes to a TAFKAL80ETC concert";
private const string conjuredItem = "Conjured";
private const string sulfuras = "Sulfuras, Hand of Ragnaros";
IList<Item> Items;
public GildedRose(IList<Item> Items)
{
this.Items = Items;
}
public void UpdateQuality()
{
foreach (var item in Items.Where(constantItem => !constantItem.Name.Contains(sulfuras)))
{
if (item.Name is agedBrie)
{
IncrementItemQuality(item);
}
else if (item.Name is concertTickets)
{
HandleBackstagePasses(item);
}
else DecrementItemQuality(item);
DecrementSellinDays(item);
HandleItemPastSellin(item);
Guard.ThatItemQualityDoesNotExceedMax(item);
Guard.ThatItemQualityDoesNotExceedMin(item);
}
}
private static void HandleItemPastSellin(Item item)
{
if (item.SellIn < minSellIn)
if (item.Name != agedBrie)
DecrementItemQuality(item);
else
IncrementItemQuality(item);
}
private static void DecrementSellinDays(Item item)
{
item.SellIn -= 1;
}
private static void HandleBackstagePasses(Item item)
{
const int eleven_days = 11;
const int six_days = 6;
if (item.SellIn <= minSellIn)
{
item.Quality = 0;
}
else if (item.SellIn < six_days)
{
item.Quality += 3;
}
else if (item.SellIn < eleven_days)
{
item.Quality += 2;
}
else IncrementItemQuality(item);
}
private static void DecrementItemQuality(Item item)
{
if (item.Name.Contains(conjuredItem))
item.Quality -= 2;
else
item.Quality -= 1;
}
private static void IncrementItemQuality(Item item)
{
item.Quality += 1;
}
}
}