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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
| unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls,MMsystem;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure DoskaCreate;
procedure FigureCreate;
procedure ClickDoskaOrFigure;
function Analysis: Boolean;
function PlayerYes:Boolean;
private
public
end;
Tdoska=class(Tpanel)
private
Fx,Fy:Integer;
FState:Integer;
public
procedure Click;override;
property PosX:Integer read Fx write Fx;
property PosY:Integer read Fy write Fy;
property State: integer read FState write FState;
end;
TFigure=class(TImage)
private
X,Y:Integer;
Fkilled: Boolean;
FTypeFigure:Byte;
FColorFigure:Byte;
public
procedure Click;override;
property PosX:Integer read X write X;
property PosY:Integer read Y write Y;
property Color:Byte read FColorFigure write FColorFigure;
property TypeFigure:Byte read FTypeFigure write FTypeFigure;
end;
const
DoskaPosTop=70;
DoskaPosLeft=50;
DoskaWidth= 8;
DoskaHeight=8;
CellWidth=55;
CellHeight=55;
CountFigure=32;
var
Form1: TForm1;
doska:array[0..DoskaWidth,0..DoskaHeight] of Tdoska;
massfigure:array[1..countfigure] of Tfigure;
figure,figure1:tfigure;
clickd:tdoska;
Player:Integer=1;
TypeShowDoska:Integer=1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
DoskaCreate;
FigureCreate;
end;
procedure TForm1.DoskaCreate;
var
x,y,PosTop,PosLeft:integer;
begin
PosTop:=DoskaPosTop+DoskaHeight*CellHeight;
PosLeft:=DoskaPosLeft;
for x:=1 to DoskaWidth do
for y:=1 to DoskaHeight do begin
doska[x,y]:=tdoska.create(self);
with doska[x,y] do begin
parent:=form1;
PosX:=X; PosY:=Y;
Width:= CellWidth;
Height:=CellHeight;
Top:=PosTop-y*CellHeight;
Left:=PosLeft+(x-1)*CellWidth;
if (x+y) mod 2=1 then Color:=clBlack else color:=clwhite;
end;
end;
end;
procedure TForm1.FigureCreate;
var
i:Integer;
Procedure AtrPicture(PosX,PosY:integer;WayPicture:string);
begin
MassFigure[i].Picture.LoadFromFile(WayPicture);
MassFigure[i].Parent:=doska[PosX,PosY];
MassFigure[i].Transparent:=True;
MassFigure[i].PosX:=PosX;
MassFigure[i].PosY:=PosY;
end;
begin
for i:=1 to CountFigure do
begin
MassFigure[i]:=TFigure.Create(Self);
case i of
1..8:
begin
MassFigure[i].TypeFigure:=1;
MassFigure[i].Color:=1;
AtrPicture(i,2,'пешка белая.bmp');
end;
9:
begin
MassFigure[9].TypeFigure:=2;
MassFigure[9].Color:=1;
AtrPicture(1,1,'Ладья белая.bmp');
end;
10:
begin
MassFigure[10].TypeFigure:=2;
MassFigure[10].Color:=1;
AtrPicture(8,1,'Ладья белая.bmp');
end;
11:
begin
MassFigure[11].TypeFigure:=4;
MassFigure[11].Color:=1;
AtrPicture(3,1,'слон белый.bmp');
end;
12:
begin
MassFigure[12].TypeFigure:=4;
MassFigure[12].Color:=1;
AtrPicture(6,1,'слон белый.bmp');
end;
13:
begin
MassFigure[13].TypeFigure:=3;
MassFigure[13].Color:=1;
AtrPicture(7,1,'конь белый.bmp');
end;
14:
begin
MassFigure[14].TypeFigure:=3;
MassFigure[14].Color:=1;
AtrPicture(2,1,'конь белый.bmp');
end;
15:
begin
MassFigure[15].TypeFigure:=6;
MassFigure[15].Color:=1;
AtrPicture(5,1,'король белый.bmp');
end;
16:
begin
MassFigure[16].TypeFigure:=5;
MassFigure[16].Color:=1;
AtrPicture(4,1,'ферзь белый.bmp');
end;
17:
begin
MassFigure[17].TypeFigure:=5;
MassFigure[17].Color:=2;
AtrPicture(5,8,'ферзь черный.bmp');
end;
18:
begin
MassFigure[18].TypeFigure:=3;
MassFigure[18].Color:=2;
AtrPicture(2,8,'конь черный.bmp');
end;
19:
begin
MassFigure[19].TypeFigure:=3;
MassFigure[19].Color:=2;
AtrPicture(7,8,'конь черный.bmp');
end;
20:
begin
MassFigure[20].TypeFigure:=4;
MassFigure[20].Color:=2;
AtrPicture(6,8,'слон черный.bmp');
end;
21:
begin
MassFigure[21].TypeFigure:=4;
MassFigure[21].Color:=2;
AtrPicture(3,8,'слон черный.bmp');
end;
22:
begin
MassFigure[22].TypeFigure:=6;
MassFigure[22].Color:=2;
AtrPicture(4,8,'король черный.bmp');
end;
23:
begin
MassFigure[23].TypeFigure:=2;
MassFigure[23].Color:=2;
AtrPicture(1,8,'ладья черная.bmp');
end;
24:
begin
MassFigure[24].TypeFigure:=2;
MassFigure[24].Color:=2;
AtrPicture(8,8,'ладья черная.bmp');
end;
25..32:
begin
MassFigure[i].TypeFigure:=1;
MassFigure[i].Color:=2;
AtrPicture(i-24,7,'пешка черная.bmp');
end;
end;
end;
end;
procedure TFigure.Click;
begin
inherited;
Figure1:=TFigure(Self);
if Player= figure1.Color then Figure:= Figure1;
if Player<> figure1.Color then
begin
clickd:= doska[Figure1.PosX,Figure1.PosY];
Form1.ClickDoskaOrFigure;
end;
end;
procedure Tdoska.Click;
begin
inherited;
Clickd:=Tdoska(Self);
Form1.ClickDoskaOrFigure;
end;
procedure TForm1.ClickDoskaOrFigure;
begin
if (figure<>nil) and (Form1.PlayerYes) then
if Form1.Analysis then
begin
figure.parent:=Clickd;
figure.PosX:=clickd.PosX;
figure.PosY:=clickd.PosY;
if Player=1 then Player:=2 else Player:=1;
end
else
begin
ShowMessage('Такой ход не возможен');
Clickd:=nil;
end;
end;
function TForm1.PlayerYes: Boolean;
begin
if ((Player=1) and (Figure.Color<>1)) or ((Player=2) and (Figure.Color<>2))
then begin
ShowMessage('Не Ваш ход');
Result:=False
end
else Result:=True;
end;
function TForm1.Analysis: Boolean;
var
Diagonal,NotDiagonal:Boolean;
CellsCount,k1,k2,L,X,Y,i,j:Integer;
begin
Result:=False;
case figure.TypeFigure of
1:
begin
Diagonal:=True;
NotDiagonal:=True;
if ((figure.Color=1) and (figure.PosY=2)) or
((figure.Color=2) and (figure.PosY=7))
then CellsCount:=2
else CellsCount:=1
end;
2:
begin
Diagonal:=False;
NotDiagonal:=True;
CellsCount:=0;
end;
3:
begin
Diagonal:=TRUE;
NotDiagonal:=TRUE;
CellsCount:=0;
end;
4:
begin
Diagonal:=True;
NotDiagonal:=False;
CellsCount:=0;
end;
5:
begin
Diagonal:=True;
NotDiagonal:=True;
CellsCount:=0;
end;
6:
begin
diagonal:=True;
NotDiagonal:=True;
CellsCount:=1;
end;
end;
if NotDiagonal and ((clickd.PosX=figure.PosX) or (clickd.PosY=figure.PosY))
then Result:=True;
if Diagonal and (Abs(clickd.PosX-figure.PosX)=Abs(clickd.PosY-figure.PosY))
then Result:=True;
if ((CellsCount<Abs(clickd.PosX-figure.PosX)) or (CellsCount<Abs(clickd.PosY-figure.PosY)))
and (CellsCount<>0 )
then Result:=False;
if (Result=True) and (figure.TypeFigure<>3) and (figure.TypeFigure<>1) and (figure.TypeFigure<>5) then
begin
if clickd.PosX > figure.PosX then k1:=1;
if clickd.PosX < figure.PosX then k1:=-1;
if clickd.PosY > figure.PosY then k2:=1;
if clickd.PosY < figure.PosY then k2:=-1;
if clickd.PosX = figure.PosX then k1:=0;
if clickd.PosY = figure.PosY then k2:=0;
if Diagonal then L:=abs(figure.PosX-clickd.PosX);
if NotDiagonal then L:=abs((figure.PosX+figure.PosY)-(clickd.PosX +clickd.PosY ));
For i:=1 to L-1 do
begin
X:=Figure.PosX+i*k1;
Y:=Figure.PosY+i*k2;
for j:=1 to CountFigure do
if (doska[X,Y].PosX=massFigure[j].PosX) and (doska[X,Y].PosY=massFigure[j].PosY)
then Result:=False;
end;
end;
if (Result=True) and (figure.TypeFigure=1) then
begin
if ((Player=1) and (clickd.PosY>figure.PosY)) or ((Player=2) and (clickd.PosY<figure.PosY)) then
begin
if figure.PosX<>clickd.PosX then Result:=False;
if (Abs(clickd.PosX-figure.PosX)-Abs(clickd.PosY-figure.PosY))=0 then
for j:=1 to CountFigure do
if (clickd.PosX=massFigure[j].PosX) and (clickd.PosY=massFigure[j].PosY)
Then Result:=True;
end
else Result:=False;
end;
if figure.Typefigure=3
then
begin
if ((figure.TypeFigure=3) and
((clickd.posx=figure.posx+2) and (clickd.PosY=figure.posy+1) or
(clickd.posx=figure.posx+2) and (clickd.PosY=figure.posy-1) or
(clickd.posx=figure.posx-2) and (clickd.PosY=figure.posy+1) or
(clickd.posx=figure.posx-2) and (clickd.PosY=figure.posy-1) or
(clickd.posx=figure.posx+1) and (clickd.PosY=figure.posy+2) or
(clickd.posx=figure.posx-1) and (clickd.PosY=figure.posy+2) or
(clickd.posx=figure.posx+1) and (clickd.PosY=figure.posy-2) or
(clickd.posx=figure.posx-1) and (clickd.PosY=figure.posy-2)))
then Result:=True
else Result:=False
end;
if Result=True then
for i:=1 to CountFigure do
if massfigure[i]<>nil then
if (massfigure[i].PosX= clickd.PosX) and (massfigure[i].PosY= clickd.PosY) then
massfigure[i].Hide;
end;
end. |