-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGuiUnit.pas
More file actions
133 lines (120 loc) · 3.53 KB
/
Copy pathGuiUnit.pas
File metadata and controls
133 lines (120 loc) · 3.53 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
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
unit GuiUnit;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.Imaging.pngimage,
Vcl.StdCtrls, Vcl.Grids, Vcl.ColorGrd,
SudokuUnit, FMX.Graphics;
type
TForm1 = class(TForm)
Image1: TImage;
StringGrid1: TStringGrid;
Button1: TButton;
Button2: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure StringGrid1SetEditText(Sender: TObject; ACol, ARow: Integer;
const Value: String);
procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
private
{ Private declarations }
ques: array [0..9, 0..9] of Boolean;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
for var i := 0 to 8 do begin
for var j := 0 to 8 do begin
ques[i][j] := False;
end;
end;
end;
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
begin
var value: string := '';
var Board: SudokuBoard;
for var i := 0 to 8 do begin
for var j := 0 to 8 do begin
if StringGrid1.Cells[j, i].IsEmpty then Value := value + '0'
else value := value + StringGrid1.Cells[j, i];
end;
end;
Board := SudokuBoard.Create(value);
Board.Solve;
var c: Byte := 1;
for var i := 0 to 8 do begin
for var j := 0 to 8 do begin
StringGrid1.Cells[j, i] := Board.print[c];
Inc(c);
end;
end;
Board.Destroy;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
for var i := 0 to 8 do begin
for var j := 0 to 8 do begin
StringGrid1.Cells[j, i] := '';
ques[i][j] := False;
end;
end;
end;
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
//temp
with StringGrid1.Canvas do begin
FillRect(Rect);
if (ACol = 3) or (ACol = 6) then begin
Pen.Color := clBlack;
Pen.Width := 3;
MoveTo(Rect.Left, Rect.Top);
LineTo(Rect.Left, Rect.Bottom);
end;
if (ACol = 2) or (ACol = 5) then begin
Pen.Color := clBlack;
Pen.Width := 3;
MoveTo(Rect.Right, Rect.Top);
LineTo(Rect.Right, Rect.Bottom);
end;
if (ARow = 3) or (ARow = 6) then begin
Pen.Color := clBlack;
Pen.Width := 3;
MoveTo(Rect.Left, Rect.Top);
LineTo(Rect.Right, Rect.Top);
end;
if (ARow = 2) or (ARow = 5) then begin
Pen.Color := clBlack;
Pen.Width := 3;
MoveTo(Rect.Left, Rect.Bottom);
LineTo(Rect.Right, Rect.Bottom);
end;
if ques[ARow][Acol] then Font.Color := clRed
else Font.Color := clBlue;
Font.Style := [fsBold];
TextRect(Rect, Rect.Left + 18, Rect.Top + 10,StringGrid1.Cells[ACol, ARow]);
end;
end;
procedure TForm1.StringGrid1SetEditText(Sender: TObject; ACol, ARow: Integer;
const Value: String);
begin
with Sender as TStringGrid do begin
if (length(value) > 1) then begin
Cells[ACol,ARow] := copy(value,1,length (value)-1);
end
else if not((Cells[Acol, ARow] = '1') or (Cells[Acol, ARow] = '2') or (Cells[Acol, ARow] = '3') or (Cells[Acol, ARow] = '4') or (Cells[Acol, ARow] = '5') or (Cells[Acol, ARow] = '6') or (Cells[Acol, ARow] = '7') or (Cells[Acol, ARow] = '8') or (Cells[Acol, ARow] = '9')) then
Cells[ACol,ARow] := '';
if (length(value) = 1) then ques[ARow][ACol] := True
else ques[ARow][ACol] := False;
end;
end;
end.