-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSquareClass.pas
More file actions
74 lines (64 loc) · 1.92 KB
/
SquareClass.pas
File metadata and controls
74 lines (64 loc) · 1.92 KB
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
unit SquareClass;
interface
uses crt;
type
Square = class
private
x, y, size, number, errorCode: integer;
function computeBgColor: integer;
public
constructor Create(_x, _y, _size, _number, _errorCode: integer);
begin
self.x := _x;
self.y := _y;
self.size := _size;
self.number := _number;
self.errorCode := _errorCode;
end;
procedure drawSquare;
end;
implementation
function Square.computeBgColor: integer;
begin
var color: integer;
case self.number of
-1: color := LightGray;
2: color := LightBlue;
4: color := LightCyan;
8: color := LightRed;
16: color := LightGreen;
32: color := LightMagenta;
64: color := Brown;
128: color := Blue;
256: color := Cyan;
512: color := Red;
1024: color := Green;
2048: color := Magenta;
end;
result := color;
end;
procedure Square.drawSquare;
begin
var color := computeBgColor();
var strNumber: string;
strNumber := intToStr(self.number);
gotoXY(self.x, self.y);
for var i := 0 to self.size - 1 do
begin
for var j := 0 to self.size - 1 do
begin
if (j >= 1) and (j <= length(strNumber)) and (i = 1) and (self.number <> self.errorCode) then
begin
textColor(white);
textBackground(color);
write(strNumber[j]);
end else begin
textColor(color);
textBackground(color);
write('@');
end;
end;
gotoXY(self.x, whereY + 1);
end;
end;
end.