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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
| unit kyrs2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, Menus, ComCtrls, Buttons;
type
Pin = array of TPanel;
TForm1 = class (TForm)
Panel1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
Panel4: TPanel;
Panel5: TPanel;
Panel6: TPanel;
Panel7: TPanel;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
Edit6: TEdit;
MainMenu1: TMainMenu;
N1: TMenuItem;
N3: TMenuItem;
StatusBar1: TStatusBar;
Timer1: TTimer;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Edit7: TEdit;
UpDown1: TUpDown;
N2: TMenuItem;
N4: TMenuItem;
N5: TMenuItem;
N7: TMenuItem;
L1: TMenuItem;
Timer2: TTimer;
procedure Beg (Sen: TObject);
procedure PanelClick (Sender: TObject);
procedure Mov (Pan1, Pan2: TPanel; Ed: TEdit)
procedure Hig (Pan: Pin; Tow: TPanel; Ed1, Ed2: TEdit)
procedure Fin;
procedure Sel (Pan1: TObject; Pan: Pin; Ed1, Ed2, Ed3: TEdit)
procedure Pos (Pan: TPanel)
procedure FormCreate (Sender: TObject);
procedure Panel3Click (Sender: TObject);
procedure Panel4Click (Sender: TObject);
procedure Panel2Click (Sender: TObject);
procedure N2Click (Sender: TObject);
procedure Timer1Timer (Sender: TObject);
procedure N4Click (Sender: TObject);
procedure N7Click (Sender: TObject);
procedure FormClick (Sender: TObject);
procedure N5Click (Sender: TObject);
procedure L1Click (Sender: TObject);
procedure Timer2Timer (Sender: TObject);
private
{Private declarations}
public
{Public declarations}
end;
var
i, j, t, n: integer;
f: boolean;
p: Pin;
m, s: string;
v: TPanel;
Form1: TForm1;
implementation
uses Sved;
{$ R *. Dfm}
procedure TForm1.FormCreate (Sender: TObject);
begin
Application.HelpFile: = 'Help.hpl';
Panel2.Height: = UpDown1.Position * 20 +40;
Panel3.Height: = UpDown1.Position * 20 +40;
Panel4.Height: = UpDown1.Position * 20 +40;
Panel2.Top: = Panel5.Top-UpDown1.Position * 20-30;
Panel3.Top: = Panel5.Top-UpDown1.Position * 20-30;
Panel4.Top: = Panel5.Top-UpDown1.Position * 20-30;
Form1.Left: = 163;
Form1.Top: = 163;
f: = False;
Panel1.Enabled: = False;
Timer1.Enabled: = False;
Label1.Visible: = False;
Label2.Visible: = False;
t: = 0;
StatusBar1.Panels.Items [1]. Text: = 'Кол-во шагов:' + IntToStr (t);
m: = '00 ';
s: = '00 ';
StatusBar1.Panels.Items [0]. Text: = 'Время игры:' + m + ':' + s;
Edit1.Text: = IntToStr (UpDown1.Position)
Edit2.Text: = IntToStr (0);
Edit3.Text: = IntToStr (0);
Edit5.Text: ='';
Edit6.Text: ='';
end;
procedure TForm1.Panel2Click (Sender: TObject);
begin
Label2.Caption: ='';
if (f = True) and (v.Color = clLime) and ((v.Caption <= Edit4.Text) or (Edit4.Text ='')) then
begin
t: = t +1;
StatusBar1.Panels.Items [1]. Text: = 'Кол-во шагов:' + IntToStr (t);
Pos (v);
Edit1.Text: = IntToStr (StrToInt (Edit1.Text) +1);
Mov (v, Panel5, Edit1)
Edit4.Text: = v.Caption;
Hig (p, Panel3, Edit5, Edit2)
Hig (p, Panel4, Edit6, Edit3)
Fin;
v.Color: = clGreen;
Label2.Caption: = 'Выберите диск для перемещения';
end
else
Label2.Caption: = 'Ход НЕ верный! Попробуйте снова ';
end;
procedure TForm1.Panel3Click (Sender: TObject);
begin
Label2.Caption: ='';
if (f = True) and (v.Color = clLime) and ((v.Caption <= Edit5.Text) or (Edit5.Text ='')) then
begin
t: = t +1;
StatusBar1.Panels.Items [1]. Text: = 'Кол-во шагов:' + IntToStr (t);
Pos (v);
Edit2.Text: = IntToStr (StrToInt (Edit2.Text) +1);
Mov (v, Panel7, Edit2)
Edit5.Text: = v.Caption;
Hig (p, Panel2, Edit4, Edit1)
Hig (p, Panel4, Edit6, Edit3)
Fin;
v.Color: = clGreen;
Label2.Caption: = 'Выберите диск для перемещения';
end
else
Label2.Caption: = 'Ход НЕ верный! Попробуйте снова ';
end;
procedure TForm1.Panel4Click (Sender: TObject);
begin
Label2.Caption: ='';
if (f = True) and (v.Color = clLime) and ((v.Caption <= Edit6.Text) or (Edit6.Text ='')) then
begin
t: = t +1;
StatusBar1.Panels.Items [1]. Text: = 'Кол-во шагов:' + IntToStr (t);
Pos (v);
Edit3.Text: = IntToStr (StrToInt (Edit3.Text) +1);
Mov (v, Panel6, Edit3)
Edit6.Text: = v.Caption;
Hig (p, Panel2, Edit4, Edit1)
Hig (p, Panel3, Edit5, Edit2)
Fin;
v.Color: = clGreen;
Label2.Caption: = 'Выберите диск для перемещения';
end
else
Label2.Caption: = 'Ход НЕ верный! Попробуйте снова ';
end;
procedure TForm1.Pos (Pan: TPanel)
begin
if (Pan.Left = StrToInt (FloatToStr (90-Pan.Width / 2)))
then Edit1.Text: = IntToStr (StrToInt (Edit1.Text) -1);
if (Pan.Left = StrToInt (FloatToStr (300-Pan.Width / 2)))
then Edit2.Text: = IntToStr (StrToInt (Edit2.Text) -1);
if (Pan.Left = StrToInt (FloatToStr (510-Pan.Width / 2)))
then Edit3.Text: = IntToStr (StrToInt (Edit3.Text) -1);
end;
procedure TForm1.Sel (Pan1: TObject; Pan: Pin; Ed1, Ed2, Ed3: TEdit)
begin
if ((Pan1 as TPanel). Caption = Ed1.Text) or ((Pan1 as TPanel). Caption = Ed2.Text) or ((Pan1 as TPanel). Caption = Ed3.Text)
then
begin
for i: = 1 to UpDown1.Position do
Pan [i]. Color: = clGreen;
(Pan1 as TPanel). Color: = clLime;
Label2.Caption: = 'Переместить диск на другой колышек';
end;
end;
procedure TForm1.Fin;
begin
if (Edit2.Text = IntToStr (UpDown1.Position)) or (Edit3.Text = IntToStr (UpDown1.Position)) then
begin
Panel1.Enabled: = False;
Label1.Visible: = True;
Label2.Visible: = False;
Timer1.Enabled: = False;
end;
end;
procedure TForm1.Hig (Pan: Pin; Tow: TPanel; Ed1, Ed2: TEdit)
begin
if StrToInt (Ed2.Text) = 1 then
for i: = 1 to UpDown1.Position do
if (Tow.Left = Pan [i]. Left + Pan [i] .Width/2-5) then
Ed1.Text: = Pan [i]. Caption;
if StrToInt (Ed2.Text)> 1 then
for i: = UpDown1.Position downto 2 do
for j: = UpDown1.Position-1 downto 1 do
if (Tow.Left = Pan [i]. Left + Pan [i] .Width/2-5) and (Tow.Left = Pan [j]. Left + Pan [j] .Width/2-5)
then
if (StrToInt (Pan [i]. Caption)> StrToInt (Pan [j]. Caption))
then Ed1.Text: = Pan [j]. Caption;
if StrToInt (Ed2.Text) = 0 then
Ed1.Text: ='';
end;
procedure TForm1.Mov (Pan1, Pan2: TPanel; Ed: TEdit)
begin
Pan1.Left: = StrToInt (FloatToStr (Pan2.Left + Pan2.Width/2-Pan1.Width/2));
Pan1.Top: = Pan2.Top-20 * StrToInt (Ed.Text)
end;
procedure TForm1.N2Click (Sender: TObject);
begin
Beg (Sender);
end;
procedure TForm1.Timer1Timer (Sender: TObject);
begin
s: = IntToStr (StrToInt (s) +1);
if (s = '60 ') then
begin
m: = IntToStr (StrToInt (m) +1);
s: = '00 ';
end;
if Length (s) = 1 then s: = '0 '+ IntToStr (StrToInt (s));
if Length (m) = 1 then m: = '0 '+ IntToStr (StrToInt (m) +1);
StatusBar1.Panels.Items [0]. Text: = 'Время игры:' + m + ':' + s;
end;
procedure TForm1.PanelClick (Sender: TObject);
begin
if ((Sender as TPanel). Caption = Edit4.Text) or ((Sender as TPanel). Caption = Edit5.Text) or ((Sender as TPanel). Caption = Edit6.Text)
then
begin
for i: = 1 to UpDown1.Position do
p [i]. Color: = clGreen;
(Sender as TPanel). Color: = clLime;
v: = (Sender as TPanel)
f: = True;
Label2.Caption: = 'Переместить диск на другой колышек';
end;
end;
procedure TForm1.Beg (Sen: TObject);
begin
if MessageDlg ('Вы уверены, что хотите закончить эту игру и начать новую?', mtInformation, [mbOK, mbCancel], 0) = 1
then
begin
for i: = 1 to n do
p [i]. Destroy;
FormCreate (Sen);
Panel1.Enabled: = True;
Timer1.Enabled: = True;
Label2.Visible: = True;
Label2.Caption: = 'Выберите диск для перемещения';
n: = UpDown1.Position;
SetLength (p, UpDown1.Position +1);
for i: = 1 to UpDown1.Position do
begin
Edit1.Text: = IntToStr (i);
Edit4.Text: = IntToStr (1);
p [i]: = TPanel.Create (Self);
p [i]. Height: = 20;
p [i]. Width: = Panel5.Width-16 * (UpDown1.Position-i +1);
p [i]. Left: = (Panel2.Left +5)-StrToInt (FloatToStr (p [i]. Width / 2));
p [i]. Top: = Panel5.Top-p [i]. Height * (UpDown1.Position-i +1);
p [i]. Color: = clGreen;
p [i]. Anchors: = [akLeft, akBottom];
p [i]. Font.Color: = clYellow;
p [i]. Font.Style: = [fsBold];
p [i]. Caption: = IntToStr (i);
p [i]. OnClick: = PanelClick;
p [i]. Parent: = Panel1;
end;
end;
end;
procedure TForm1.N4Click (Sender: TObject);
begin
if MessageDlg ('Вы уверены, что хотите закончить игру и выйти?', mtInformation, [mbOK, mbCancel], 0) = 1
then Close;
end;
procedure TForm1.N7Click (Sender: TObject);
begin
AboutBox.Show;
end;
procedure TForm1.FormClick (Sender: TObject);
begin
AboutBox.Close;
end;
procedure TForm1.N5Click (Sender: TObject);
begin
Application.HelpJump ('IDH_main');
end;
procedure TForm1.L1Click (Sender: TObject);
begin
Beg (Sender);
i: = 1;
Timer2.Enabled: = True;
end;
procedure TForm1.Timer2Timer (Sender: TObject);
begin
if (i <UpDown1.Position) then i: = i +1;
end;
end. |