generated from Coding-Cuddles/bootstrap-cpp-kata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gilded_rose.h
79 lines (69 loc) · 2.23 KB
/
gilded_rose.h
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
#include <vector>
#include <string>
#include <memory>
class Item {
public:
Item() = delete;
Item(std::string name, int sell_in, int quality)
: name(std::move(name)), sell_in(sell_in), quality(quality)
{
}
std::string name;
int sell_in;
int quality;
};
class GildedRose {
public:
GildedRose() = default;
void add_item(std::string name, int sell_in, int quality)
{
items.emplace_back(std::make_unique<Item>(name, sell_in, quality));
}
void update_quality()
{
for (auto& item : items) {
if (item->name != "Aged Brie" &&
item->name != "Backstage passes to a TAFKAL80ETC concert") {
if (item->quality > 0) {
if (item->name != "Sulfuras, Hand of Ragnaros")
item->quality--;
}
}
else {
if (item->quality < 50) {
item->quality++;
if (item->name == "Backstage passes to a TAFKAL80ETC concert") {
if (item->sell_in < 11) {
if (item->quality < 50)
item->quality++;
}
if (item->sell_in < 6) {
if (item->quality < 50)
item->quality++;
}
}
}
}
if (item->name != "Sulfuras, Hand of Ragnaros")
item->sell_in--;
if (item->sell_in < 0) {
if (item->name != "Aged Brie") {
if (item->name != "Backstage passes to a TAFKAL80ETC concert") {
if (item->quality > 0) {
if (item->name != "Sulfuras, Hand of Ragnaros")
item->quality--;
}
}
else {
item->quality = 0;
}
}
else {
if (item->quality < 50)
item->quality++;
}
}
}
}
std::vector<std::unique_ptr<Item>> items;
};