-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgilded_rose_refactored.py
80 lines (64 loc) · 1.81 KB
/
gilded_rose_refactored.py
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
class Item:
def __init__(self, quality, days_remaining):
self._quality = quality
self._days_remaining = days_remaining
@property
def quality(self):
return self._quality
@property
def days_remaining(self):
return self._days_remaining
def tick(self):
return
class Normal(Item):
def tick(self):
self._days_remaining -= 1
if self._quality == 0:
return
self._quality -= 1
if self._days_remaining <= 0:
self._quality -= 1
class AgedBrie(Item):
def tick(self):
self._days_remaining -= 1
if self._quality >= 50:
return
self._quality += 1
if self._days_remaining <= 0:
self._quality += 1
class ConjuredManaCake(Item):
def tick(self):
self._days_remaining -= 1
if self._quality == 0:
return
self._quality -= 2
if self._days_remaining <= 0:
self._quality -= 2
class BackstagePasses(Item):
def tick(self):
self._days_remaining -= 1
if self._quality >= 50:
return
if self._days_remaining < 0:
self._quality = 0
return
self._quality += 1
if self._days_remaining < 10:
self._quality += 1
if self._days_remaining < 5:
self._quality += 1
return
DEFAULT_ITEM = Item
NAME_TO_ITEM = {
"Normal": Normal,
"Aged Brie": AgedBrie,
"Backstage passes to a TAFKAL80ETC concert": BackstagePasses,
"Conjured Mana Cake": ConjuredManaCake,
}
class GildedRose:
@classmethod
def for_item(cls, name, quality, days_remaining):
return cls.class_for(name)(quality, days_remaining)
@staticmethod
def class_for(name):
return NAME_TO_ITEM.get(name, DEFAULT_ITEM)