-
Notifications
You must be signed in to change notification settings - Fork 0
/
gilded_rose.py
executable file
·82 lines (56 loc) · 1.83 KB
/
gilded_rose.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
81
82
# -*- coding: utf-8 -*-
class GildedRose(object):
def __init__(self, items):
self.items = items
def update_quality(self):
for item in self.items:
if item.name == "Sulfuras, Hand of Ragnaros":
LegendaryItem(item).update()
continue
if item.name == "Aged Brie":
AgedItem(item).update()
continue
if item.name == "Backstage passes to a TAFKAL80ETC concert":
TicketItem(item).update()
continue
RichItem(item).update()
class RichItem:
def __init__(self, item):
self.item = item
def update(self):
self.decrease_quality()
self.item.sell_in -= 1
if self.item.sell_in < 0:
self.decrease_quality()
def increase_quality(self, by=1):
if self.item.quality < 50:
self.item.quality += by
def decrease_quality(self):
if self.item.quality > 0:
self.item.quality -= 1
class LegendaryItem(RichItem):
def update(self):
pass
class AgedItem(RichItem):
def update(self):
self.increase_quality()
self.item.sell_in -= 1
if self.item.sell_in < 0:
self.increase_quality()
class TicketItem(RichItem):
def update(self):
self.increase_quality()
if self.item.sell_in in range(6, 11):
self.increase_quality()
if self.item.sell_in in range(0, 6):
self.increase_quality(by=2)
self.item.sell_in -= 1
if self.item.sell_in < 0:
self.item.quality = 0
class Item:
def __init__(self, name, sell_in, quality):
self.name = name
self.sell_in = sell_in
self.quality = quality
def __repr__(self):
return "%s, %s, %s" % (self.name, self.sell_in, self.quality)