Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunc/touch/Unit1.pas

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (show annotations) (download) (as text)
Tue Apr 4 10:02:13 2017 UTC (7 years, 1 month ago) by yamat0jp
File MIME type: text/x-pascal
File size: 7442 byte(s)
悪意あるソフトウェアと判断されているようです touch
1 unit Unit1;
2
3 interface
4
5 uses
6 System.SysUtils, System.Types, System.UITypes, System.Classes,
7 System.Variants,
8 FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls,
9 FMX.Layouts, FMX.ExtCtrls;
10
11 const
12 WidCount = 10;
13 HeiCount = 8;
14 Size = 32;
15 {$IFDEF MSWINDOWS}
16 Mass = 32;
17 {$ELSE}
18 Mass = 64;
19 {$ENDIF}
20 Hit = 60;
21
22 type
23
24 TData = class
25 ImageIndex: integer;
26 Enabled: Boolean;
27 end;
28
29 TForm1 = class(TForm)
30 ImageControl1: TImageControl;
31 Panel1: TPanel;
32 Button1: TButton;
33 Button2: TButton;
34 Label1: TLabel;
35 procedure FormCreate(Sender: TObject);
36 procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
37 Shift: TShiftState; X, Y: Single);
38 procedure Button2Click(Sender: TObject);
39 procedure Button1Click(Sender: TObject);
40 procedure Panel1Paint(Sender: TObject; Canvas: TCanvas;
41 const ARect: TRectF);
42 procedure FormDestroy(Sender: TObject);
43 procedure Button1Tap(Sender: TObject; const Point: TPointF);
44 procedure Button2Tap(Sender: TObject; const Point: TPointF);
45 private
46 { private ���� }
47 Data: array [0 .. WidCount - 1, 0 .. HeiCount - 1] of TData;
48 function CheckResult: Boolean;
49 function ScanResult: integer;
50 procedure RemoveItems;
51 procedure ChangeItems(X, Y: integer);
52 public
53 { public ���� }
54 Score: integer;
55 procedure NewGame;
56 procedure GameOver;
57 end;
58
59 var
60 Form1: TForm1;
61
62 implementation
63
64 {$R *.fmx}
65
66 { TForm1 }
67
68 procedure TForm1.Button1Click(Sender: TObject);
69 begin
70 NewGame;
71 end;
72
73 procedure TForm1.Button1Tap(Sender: TObject; const Point: TPointF);
74 begin
75 Button1Click(Sender);
76 end;
77
78 procedure TForm1.Button2Click(Sender: TObject);
79 begin
80 Close;
81 end;
82
83 procedure TForm1.Button2Tap(Sender: TObject; const Point: TPointF);
84 begin
85 Button2Click(Sender);
86 end;
87
88 procedure TForm1.ChangeItems(X, Y: integer);
89 var
90 i: integer;
91 s: TData;
92 begin
93 s := Data[X, Y];
94 if (s.Enabled = true) and (s.ImageIndex <> 0) then
95 begin
96 i := s.ImageIndex;
97 s.Enabled := false;
98 end
99 else
100 begin
101 Exit;
102 end;
103 if X > 0 then
104 begin
105 s := Data[X - 1, Y];
106 if (s.Enabled = true) and (s.ImageIndex = i) then
107 ChangeItems(X - 1, Y);
108 end;
109 if X < WidCount - 1 then
110 begin
111 s := Data[X + 1, Y];
112 if (s.Enabled = true) and (s.ImageIndex = i) then
113 ChangeItems(X + 1, Y);
114 end;
115 if Y > 0 then
116 begin
117 s := Data[X, Y - 1];
118 if (s.Enabled = true) and (s.ImageIndex = i) then
119 ChangeItems(X, Y - 1);
120 end;
121 if Y < HeiCount - 1 then
122 begin
123 s := Data[X, Y + 1];
124 if (s.Enabled = true) and (s.ImageIndex = i) then
125 ChangeItems(X, Y + 1);
126 end;
127 end;
128
129 function TForm1.CheckResult: Boolean;
130 var
131 i, j, m: integer;
132 begin
133 for i := 0 to WidCount - 1 do
134 for j := HeiCount - 1 downto 1 do
135 begin
136 m := Data[i, j].ImageIndex;
137 if m = 0 then
138 begin
139 break;
140 end
141 else if m = Data[i, j - 1].ImageIndex then
142 begin
143 result := true;
144 Exit;
145 end;
146 end;
147 for j := HeiCount - 1 downto 0 do
148 for i := 0 to WidCount - 2 do
149 begin
150 m := Data[i, j].ImageIndex;
151 if m = 0 then
152 begin
153 continue;
154 end
155 else if m = Data[i + 1, j].ImageIndex then
156 begin
157 result := true;
158 Exit;
159 end;
160 end;
161 result := false;
162 end;
163
164 procedure TForm1.FormCreate(Sender: TObject);
165 var
166 i, j: integer;
167 begin
168 for i := 0 to WidCount - 1 do
169 for j := 0 to HeiCount - 1 do
170 Data[i, j] := TData.Create;
171 Panel1.Width := WidCount * Mass;
172 Panel1.Height := HeiCount * Mass;
173 NewGame;
174 end;
175
176 procedure TForm1.FormDestroy(Sender: TObject);
177 var
178 i, j: integer;
179 begin
180 for i := 0 to WidCount - 1 do
181 for j := 0 to HeiCount - 1 do
182 Data[i, j].Free;
183 end;
184
185 procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
186 Shift: TShiftState; X, Y: Single);
187 var
188 s: TTouch;
189 i, j, m: integer;
190 t: TData;
191 begin
192 s.Location := PointF(X, Y);
193 i := Trunc(X / Mass);
194 j := Trunc(Y / Mass);
195 ChangeItems(i, j);
196 m := ScanResult;
197 if m <= 1 then
198 begin
199 Data[i, j].Enabled := true;
200 end
201 else
202 begin
203 inc(Score, Hit * m * m);
204 end;
205 for i := 0 to WidCount - 1 do
206 for j := 0 to HeiCount - 1 do
207 begin
208 t := Data[i, j];
209 if t.Enabled = false then
210 begin
211 t.ImageIndex := 0;
212 t.Enabled := true;
213 end;
214 end;
215 DoPaint(Panel1.Canvas, Panel1.BoundsRect);
216 Sleep(200);
217 RemoveItems;
218 if CheckResult = false then
219 GameOver;
220 end;
221
222 procedure TForm1.GameOver;
223 var
224 i, j: integer;
225 X: Boolean;
226 begin
227 X := false;
228 for i := 0 to WidCount - 1 do
229 for j := 0 to HeiCount - 1 do
230 if Data[i, j].ImageIndex <> 0 then
231 begin
232 X := true;
233 break;
234 end;
235 if X = false then
236 inc(Score, 10000);
237 Label1.Text := 'Score ' + IntToStr(Score);
238 Label1.Visible := true;
239 end;
240
241 procedure TForm1.NewGame;
242 var
243 i, j, m: integer;
244 s: TData;
245 begin
246 Randomize;
247 m := ImageControl1.Bitmap.Width div Size;
248 for i := 0 to WidCount - 1 do
249 for j := 0 to HeiCount - 1 do
250 begin
251 s := Data[i, j];
252 s.ImageIndex := 1 + Random(m - 1);
253 s.Enabled := true;
254 end;
255 DoPaint(Panel1.Canvas, ClientRect);
256 Score := 0;
257 Label1.Visible := false;
258 Panel1.Repaint;
259 end;
260
261 procedure TForm1.Panel1Paint(Sender: TObject; Canvas: TCanvas;
262 const ARect: TRectF);
263 var
264 i, j, k: integer;
265 m, n: Single;
266 begin
267 for i := 0 to WidCount - 1 do
268 for j := 0 to HeiCount - 1 do
269 begin
270 k := Data[i, j].ImageIndex * Size;
271 m := i * Mass;
272 n := j * Mass;
273 Canvas.DrawBitmap(ImageControl1.Bitmap, RectF(k, 0, k + Size, Size),
274 RectF(m, n, m + Mass, n + Mass), 1);
275 end
276 end;
277
278 procedure TForm1.RemoveItems;
279 var
280 i, j: integer;
281 X, Y: Boolean;
282 begin
283 repeat
284 Y := true;
285 for i := 0 to WidCount - 1 do
286 begin
287 X := false;
288 for j := HeiCount - 1 downto 1 do
289 begin
290 if (X = true) or (Data[i, j].ImageIndex = 0) then
291 begin
292 X := true;
293 Data[i, j].ImageIndex := Data[i, j - 1].ImageIndex;
294 if (Y = true) and (Data[i, j].ImageIndex <> 0) then
295 Y := false;
296 end;
297 end;
298 if X = true then
299 Data[i, 0].ImageIndex := 0;
300 end;
301 until Y = true;
302 Panel1.Repaint;
303 Sleep(50);
304 repeat
305 X := false;
306 Y := true;
307 for i := 0 to WidCount - 2 do
308 if (X = true) or (Data[i, HeiCount - 1].ImageIndex = 0) then
309 begin
310 X := true;
311 for j := 0 to HeiCount - 1 do
312 begin
313 Data[i, j].ImageIndex := Data[i + 1, j].ImageIndex;
314 end;
315 if (Y = true) and (Data[i, HeiCount - 1].ImageIndex <> 0) then
316 Y := false;
317 end;
318 if (Y = false) and (Data[WidCount - 1, HeiCount - 1].ImageIndex <> 0) then
319 for j := 0 to HeiCount - 1 do
320 Data[WidCount - 1, j].ImageIndex := 0;
321 Panel1.Repaint;
322 until Y = true;
323 end;
324
325 function TForm1.ScanResult: integer;
326 var
327 i, j: integer;
328 begin
329 result := 0;
330 for i := 0 to WidCount - 1 do
331 for j := 0 to HeiCount - 1 do
332 if Data[i, j].Enabled = false then
333 inc(result);
334 end;
335
336 end.

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26