generated from emilybache/GildedRose-Refactoring-Kata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ROSE.PAS
137 lines (117 loc) · 3.97 KB
/
ROSE.PAS
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
unit Rose;
interface
type
Item = record { 260b memory }
Name: string;
SellIn: Integer;
Quality: Integer;
end;
Items = array [0..251] of Item; { 64kb memory }
ListOfItems = record
Elements: ^Items;
Length: Word;
end;
procedure ResizeList(var List: ListOfItems; Size: Word);
procedure ClearList(var List: ListOfItems);
procedure InitItem(var Item: Item; Name: string; SellIn: Integer; Quality: Integer);
function StrItem(Item: Item): string;
procedure UpdateQuality(Items: ListOfItems);
implementation
procedure ResizeList(var List: ListOfItems; Size: Word);
begin
List.Length := Size;
GetMem(List.Elements, Size * SizeOf(Item));
end;
procedure ClearList(var List: ListOfItems);
begin
FreeMem(List.Elements, List.Length * SizeOf(Item));
List.Length := 0;
end;
procedure InitItem(var Item: Item; Name: string; SellIn: Integer; Quality: Integer);
begin
Item.Name := Name;
Item.SellIn := SellIn;
Item.Quality := Quality;
end;
function StrItem(Item: Item): string;
var SellInStr: string;
QualityStr: string;
begin
Str(Item.SellIn, SellInStr);
Str(Item.Quality, QualityStr);
StrItem := Item.Name + ', ' + SellInStr + ', ' + QualityStr;
end;
procedure UpdateQuality(Items: ListOfItems);
var I: Word;
begin
for I := 0 to Items.Length-1 do
begin
if (Items.Elements^[I].Name <> 'Aged Brie') and
(Items.Elements^[I].Name <> 'Backstage passes to a TAFKAL80ETC concert') then
begin
if Items.Elements^[I].Quality > 0 then
begin
if Items.Elements^[I].Name <> 'Sulfuras, Hand of Ragnaros' then
begin
Items.Elements^[I].Quality := Items.Elements^[I].Quality - 1;
end;
end;
end
else
begin
if Items.Elements^[I].Quality < 50 then
begin
Items.Elements^[I].Quality := Items.Elements^[I].Quality + 1;
if Items.Elements^[I].Name = 'Backstage passes to a TAFKAL80ETC concert' then
begin
if Items.Elements^[I].SellIn < 11 then
begin
if Items.Elements^[I].Quality < 50 then
begin
Items.Elements^[I].Quality := Items.Elements^[I].Quality + 1;
end;
end;
if Items.Elements^[I].SellIn < 6 then
begin
if Items.Elements^[I].Quality < 50 then
begin
Items.Elements^[I].Quality := Items.Elements^[I].Quality + 1;
end;
end;
end;
end;
end;
if Items.Elements^[I].Name <> 'Sulfuras, Hand of Ragnaros' then
begin
Items.Elements^[I].SellIn := Items.Elements^[I].SellIn - 1;
end;
if Items.Elements^[I].SellIn < 0 then
begin
if Items.Elements^[I].Name <> 'Aged Brie' then
begin
if Items.Elements^[I].Name <> 'Backstage passes to a TAFKAL80ETC concert' then
begin
if Items.Elements^[I].Quality > 0 then
begin
if Items.Elements^[I].Name <> 'Sulfuras, Hand of Ragnaros' then
begin
Items.Elements^[I].Quality := Items.Elements^[I].Quality - 1;
end;
end;
end
else
begin
Items.Elements^[I].Quality := Items.Elements^[I].Quality - Items.Elements^[I].Quality;
end;
end
else
begin
if Items.Elements^[I].Quality < 50 then
begin
Items.Elements^[I].Quality := Items.Elements^[I].Quality + 1;
end;
end;
end;
end;
end;
end.