-
Notifications
You must be signed in to change notification settings - Fork 0
/
Figura.pas
213 lines (172 loc) · 3.86 KB
/
Figura.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
unit Figura;
interface
uses Vcl.StdCtrls, Vcl.Graphics;
type
TShapes = (fullSquare, frameSquare, triangle, diamond);
type
TShapeArguments = record
size : integer;
brush : char;
color : TColor;
memo : TMemo;
end;
type
IShape = interface ['{DF2A928C-EB97-4431-8056-E772D660D356}']
procedure Draw;
procedure SetSize(sizeFigure : Integer);
procedure SetBrush(brush : char);
procedure SetColor(color : TColor);
procedure SetCanvas(memo : TMemo);
procedure SetArguments(Arguments : TShapeArguments);
end;
type
TShape = class abstract(TInterfacedObject, IShape)
private
sizeFigure : Integer;
brush : char;
space : char;
memo : TMemo;
color : TColor;
function DrawLine(size : Integer; brush : char) : String;
procedure SetMemo;
public
Constructor Create;
Destructor Destroy;
procedure Draw; virtual;
procedure SetSize(sizeFigure : Integer);
procedure SetBrush(brush : char);
procedure SetColor(color : TColor);
procedure SetCanvas(memo : Tmemo);
procedure SetArguments(Arguments : TShapeArguments);
end;
type
TShapeFullSquare = class(TShape)
procedure Draw; override;
end;
TShapeFrameSquare = class(TShape)
procedure Draw; override;
end;
TShapeTriangle = class(TShape)
procedure Draw; override;
end;
TShapeDiamond = class(TShape)
procedure Draw; override;
end;
type
TShapeFactory = class
function CreateShape(shape : TShapes) : IShape;
end;
implementation
{ TShape }
constructor TShape.Create;
begin
inherited;
sizeFigure := 10;
brush := '*';
space := ' ';
end;
destructor TShape.Destroy;
begin
inherited;
end;
procedure TShape.Draw;
begin
memo.Lines.Add('virtual')
end;
function TShape.DrawLine(size : Integer; brush : char) : String;
var
i : Integer;
begin
result:='';
for i:=0 to size-1 do
begin
result := result + brush;
end;
end;
procedure TShape.SetSize(sizeFigure: Integer);
begin
self.sizeFigure := sizeFigure;
end;
procedure TShape.SetBrush(brush: char);
begin
self.brush := brush;
end;
procedure TShape.SetCanvas(memo: Tmemo);
begin
self.memo := memo;
end;
procedure TShape.SetColor(color: TColor);
begin
self.color := color;
end;
procedure TShape.SetArguments(Arguments: TShapeArguments);
begin
self.sizeFigure := Arguments.size;
self.brush := Arguments.brush;
self.memo := Arguments.memo;
self.color := Arguments.color;
SetMemo;
end;
procedure TShape.SetMemo;
begin
memo.Font.Color := self.color;
end;
{ TShapeFullSquare }
procedure TShapeFullSquare.Draw;
var
i : Integer;
begin
for i := 0 to sizeFigure-1 do
begin
memo.Lines.Add(DrawLine(sizeFigure,brush));
end;
end;
{ TShapeFrameSquare }
procedure TShapeFrameSquare.Draw;
var
i : Integer;
halfSize : integer;
begin
halfSize := Round(sizeFigure / 2);
memo.Lines.Add(DrawLine(sizeFigure, Self.brush));
for i:=0 to sizeFigure-2 do
begin
memo.Lines.Add(DrawLine(1,self.brush)+DrawLine(sizeFigure+halfSize,self.space)+DrawLine(1,self.brush));
end;
memo.Lines.Add(DrawLine(sizeFigure, Self.brush));
end;
{ TShapeTriangle }
procedure TShapeTriangle.Draw;
var
i : Integer;
begin
for i := 0 to sizeFigure-1 do
begin
memo.Lines.Add(DrawLine(sizeFigure-i,self.brush));
end;
end;
{ TShapeDiamond }
procedure TShapeDiamond.Draw;
var
i : Integer;
begin
for i := 0 to sizeFigure-1 do
begin
memo.Lines.Add(DrawLine(sizeFigure-i,self.brush)+DrawLine(i*4,self.space)+DrawLine(sizeFigure-i, self.brush) );
end;
for i := sizeFigure-1 downto 0 do
begin
memo.Lines.Add(DrawLine(sizeFigure-i,self.brush)+DrawLine(i*4,self.space)+DrawLine(sizeFigure-i, self.brush));
end;
end;
{ TShapeFactory }
function TShapeFactory.CreateShape(shape: TShapes): IShape;
begin
case shape of
TShapes.fullSquare : result := TShapeFullSquare.Create;
TShapes.frameSquare : result := TShapeFrameSquare.Create;
TShapes.triangle : result := TShapeTriangle.Create;
TShapes.diamond : result := TShapeDiamond.Create;
end;
end;
end.