-
Notifications
You must be signed in to change notification settings - Fork 0
/
Unit11.pas
331 lines (290 loc) · 7.42 KB
/
Unit11.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
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
unit Unit11;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Menus, JPEG, Vcl.ExtCtrls,
Vcl.StdCtrls;
type
TAliensPuzzle = class(TForm)
MainMenu1: TMainMenu;
N1: TMenuItem;
N2: TMenuItem;
N3: TMenuItem;
N4: TMenuItem;
N221: TMenuItem;
N441: TMenuItem;
N881: TMenuItem;
N1611: TMenuItem;
Timer1: TTimer;
N5: TMenuItem;
N551: TMenuItem;
Button1: TButton;
procedure N3Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure N221Click(Sender: TObject);
procedure N441Click(Sender: TObject);
procedure N881Click(Sender: TObject);
procedure N1611Click(Sender: TObject);
procedure N32321Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormActivate(Sender: TObject);
procedure N2Click(Sender: TObject);
procedure N5Click(Sender: TObject);
procedure N551Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
alienspuzzle: Talienspuzzle;
open:TJPEGImage;
Pazl:array[1..1024] of Tbitmap;
kopia,pole:array[0..31,0..31] of integer;
path:string;
razmer,xx,yy,aktiv,score:Integer;
buf,original:TBitmap;
rez:tmodalresult;
procedure pazlgo;
procedure setka(cellx,celly,mx,my,razmerx,razmery,tolshina:integer;setkacolor:tcolor;buf:tbitmap);
//game:BOOlean;\
implementation
{$R *.dfm}
uses Unit3, Unit9, Unit8, Unit10, Unit16;
procedure TAliensPuzzle.FormActivate(Sender: TObject);
begin
if unit16.number=1 then open.LoadFromFile('ôîòîêàðòî÷êè\ÏÀÇÇË\1c.jpg');
if unit16.number=2 then open.LoadFromFile('ôîòîêàðòî÷êè\ÏÀÇÇË\2c.jpg');
if unit16.number=3 then open.LoadFromFile('ôîòîêàðòî÷êè\ÏÀÇÇË\3c.jpg');
if unit16.number=4 then open.LoadFromFile('ôîòîêàðòî÷êè\ÏÀÇÇË\4c.jpg');
if unit16.number=5 then open.LoadFromFile('ôîòîêàðòî÷êè\ÏÀÇÇË\5c.jpg');
if unit16.number=6 then open.LoadFromFile('ôîòîêàðòî÷êè\ÏÀÇÇË\6c.jpg');
original.Canvas.StretchDraw(Rect(0,0,800,800),open);
pazlgo;
Timer1.Enabled:=true;
end;
procedure TAliensPuzzle.FormCreate(Sender: TObject);
var i,j:integer;
begin
score:=0;
alienspuzzle.Cursor:=1;
Screen.MenuFont.Name := 'Fifaks 1.0 dev1'; //óñòàíîâêà øðèôòà â ìåíþ ôîðìû
Screen.MenuFont.size := 12; //óñòàíîâêà ðàçìåðà øðèôòà â ìåíþ ôîðìû
path:=ExtractFileDir(Application.ExeName);
buf:=Tbitmap.Create;
buf.Width:=1600;
buf.Height:=1600;
open:=tjpegimage.Create;
open.LoadFromFile(path+'\puzzles\bender.jpg');
original:=tbitmap.Create;
original.Width:=800;
original.Height:=800;
original.Canvas.StretchDraw(Rect(0,0,800,800),open);
for i:=0 to 31 do
for j:=0 to 31 do
begin
kopia[i,j]:=0;
pole[i,j]:=0;
end;
razmer:=4;
aktiv:=0;
pazlgo;
end;
procedure TAliensPuzzle.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var uzhe:Boolean; i,j:Integer;
begin
if (Button=mbright) and (aktiv>0) then
begin
uzhe:=false;
for i:=0 to razmer-1 do
for j:=0 to razmer-1 do
if (uzhe=False) and (kopia[i,j]=0) then
begin
uzhe:=true;
kopia[i,j]:=aktiv;
aktiv:=0;
end;
end
else
begin
uzhe:=False;
if (x>=800) and (x<=1600) and (y>=0) and (y<=800) then
begin
if (kopia[(x-800) div xx,y div yy]>0) and(aktiv=0) then
begin
aktiv:=kopia[(x-800) div xx,y div yy];
kopia[(x-800) div xx,y div yy]:=0;
uzhe:=true;
end;
if (kopia[(x-800) div xx,y div yy]=0) and(aktiv>0) and (uzhe=False) then
begin
kopia[(x-800) div xx,y div yy]:=aktiv;
aktiv:=0;
end;
end;
//sleva
if (x>=0) and (x<=800) and (y>=0) and (y<=800) then
begin
if (pole[x div xx,y div yy]>0) and(aktiv=0) then
begin
aktiv:=pole[x div xx,y div yy];
pole[x div xx,y div yy]:=0;
uzhe:=true;
end;
if (pole[x div xx,y div yy]=0) and(aktiv>0) and (uzhe=False) then
begin
pole[x div xx,y div yy]:=aktiv;
aktiv:=0;
end;
end;
end;
end;
procedure TAliensPuzzle.N1611Click(Sender: TObject);
begin
razmer:=10;
pazlgo;
Timer1.enabled:=True;
end;
procedure TAliensPuzzle.N221Click(Sender: TObject);
begin
razmer:=2;
pazlgo;
Timer1.enabled:=True;
end;
procedure TAliensPuzzle.N2Click(Sender: TObject);
begin
alienspuzzle.Close;
puzzleopen.Close;
end;
procedure TAliensPuzzle.N32321Click(Sender: TObject);
begin
razmer:=32;
pazlgo;
Timer1.enabled:=True;
end;
procedure TAliensPuzzle.N3Click(Sender: TObject);
begin
AliensPuzzle.Close;
end;
procedure TAliensPuzzle.N441Click(Sender: TObject);
begin
razmer:=4;
pazlgo;
Timer1.enabled:=True;
end;
procedure TAliensPuzzle.N551Click(Sender: TObject);
begin
razmer:=5;
pazlgo;
Timer1.enabled:=True;
end;
procedure TAliensPuzzle.N5Click(Sender: TObject);
begin
form3.show;
alienspuzzle.Close;
puzzleopen.close;
aliens.hide;
planets.hide;
theories.hide;
end;
procedure TAliensPuzzle.N881Click(Sender: TObject);
begin
razmer:=8;
pazlgo;
Timer1.enabled:=True;
end;
procedure TAliensPuzzle.Timer1Timer(Sender: TObject);
var i,j,n,tolshina,mx,my:Integer;
setkacolor:tcolor; vin:Boolean;
begin
vin:=true;
n:=1;
for i:=0 to razmer-1 do
for j:=0 to razmer-1 do
begin
if pole [i,j]<>n then vin:=False;
n:=n+1;
end;
if vin=true then begin
score:=score+1;
Timer1.Enabled:=false;
ShowMessage('Ïîçäðàâëÿþ! Òû ñîáðàë ïàççë! Òâîé ñ÷¸ò: '+inttostr(score));
alienspuzzle.Close;
end;
buf.Canvas.Brush.color:=$00BC589E;
buf.Canvas.Rectangle(0,0,1600,1600);
for i:=0 to razmer-1 do
for j:=0 to razmer-1 do begin
if pole[i,j]>0 then buf.Canvas.draw(i*xx,j*yy,pazl[pole[i,j]]);
if kopia[i,j]>0 then buf.Canvas.draw(i*XX+800,j*YY,pazl[kopia[i,j]]);
end;
tolshina:=1;
setkacolor:=clBlack;
my:=0;
mx:=0;
setka(xx,yy,mx,my,razmer,razmer,tolshina,setkacolor,buf);
mx:=800;
setka(xx,yy,mx,my,razmer,razmer,tolshina,setkacolor,buf);
if aktiv>0 then buf.Canvas.Draw(Mouse.CursorPos.X-alienspuzzle.left-(xx div 2),Mouse.CursorPos.Y-alienspuzzle.top-25-(yy div 2),pazl[aktiv]);
alienspuzzle.Canvas.Draw(0,0,buf);
end;
procedure pazlgo;
var i,n,j:Integer;
begin
for i:=0 to 31 do
for j:=0 to 31 do
begin
kopia[i,j]:=0;
pole[i,j]:=0;
//for i:=1 to 1600 d0
//Pazl[i]:=
end;
case razmer of
2: begin xx:=400; yy:=400; end;
4: begin xx:=200; yy:=200; end;
5: begin xx:=160; yy:=160; end;
8: begin xx:=100; yy:=100; end;
10: begin xx:=80; yy:=80; end;
end;
n:=1;
for i:=0 to razmer-1 do
for j:=0 to razmer-1 do
begin Pazl[n]:=tbitmap.create;
Pazl[n].width:=xx;
pazl[n].Height:=yy;
Pazl[n].canvas.copyrect(rect(0,0,xx,yy),original.Canvas,rect(i*xx,j*yy,i*xx+xx-i,j*yy+yy-1)) ;
n:=n+1;
end;
n:=1;
randomize;
while(n<=razmer*razmer) do
begin
i:=Random(razmer);
j:=Random(razmer);
if kopia[i,j]=0 then
begin
kopia[i,j]:=n;
n:=n+1;
end;
end;
end;
procedure setka(cellx,celly,mx,my,razmerx,razmery,tolshina:integer;setkacolor:tcolor;buf:tbitmap);
var i:integer;
begin
buf.canvas.pen.color:=setkacolor;
buf.canvas.pen.width:=tolshina;
for i:=0 to razmery do
begin
buf.canvas.moveto(0+mx,i*celly+my);
buf.canvas.lineto(razmerx*cellx+mx,i*celly+my);
end;
for i:=0 to razmerx do
begin
buf.canvas.moveto(i*cellx+mx,0+my);
buf.canvas.lineto(i*cellx+mx,razmery*celly+my);
end;
end;
end.