Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunc/ColorBalls/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 (6 years, 11 months ago) by yamat0jp
File MIME type: text/x-pascal
File size: 11793 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 System.UIConsts, FMX.Objects;
10
11 type
12 TColorSet = set of (csRed, csBlue, csYellow);
13
14 TData = class
15 private
16 FColor: TAlphaColor;
17 procedure SetColor(const Value: TAlphaColor);
18 public
19 ColorSet: TColorSet;
20 property Color: TAlphaColor read FColor write SetColor;
21 end;
22
23 TGridData = class
24 private
25 Count: integer;
26 Temp: integer;
27 FStrings: array [0 .. 2, 0 .. 2] of TData;
28 function GetStrings(X, Y: integer): TData;
29 procedure SetStrings(X, Y: integer; const Value: TData);
30 public
31 Size: integer;
32 Left: integer;
33 Top: integer;
34 Protect: Boolean;
35 Dummy: TData;
36 constructor Create;
37 destructor Destroy; override;
38 procedure IncData(X, Y: integer);
39 procedure Clear;
40 property Strings[X, Y: integer]: TData read GetStrings
41 write SetStrings; default;
42 end;
43
44 TGridLog = class
45 public
46 X: integer;
47 Y: integer;
48 constructor Create(X, Y: integer);
49 end;
50
51 TForm1 = class(TForm)
52 Button1: TButton;
53 Button2: TButton;
54 Button3: TButton;
55 Button4: TButton;
56 Label1: TLabel;
57 Brush1: TBrushObject;
58 Button5: TButton;
59 Label2: TLabel;
60 PaintBox1: TPaintBox;
61 procedure Button4Click(Sender: TObject);
62 procedure FormCreate(Sender: TObject);
63 procedure FormDestroy(Sender: TObject);
64 procedure Button3Click(Sender: TObject);
65 procedure PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
66 Shift: TShiftState; X, Y: Single);
67 procedure Button5Click(Sender: TObject);
68 procedure Button1Click(Sender: TObject);
69 procedure Button2Click(Sender: TObject);
70 procedure Button1Tap(Sender: TObject; const Point: TPointF);
71 procedure Button5Tap(Sender: TObject; const Point: TPointF);
72 procedure Button2Tap(Sender: TObject; const Point: TPointF);
73 procedure Button3Tap(Sender: TObject; const Point: TPointF);
74 procedure Button4Tap(Sender: TObject; const Point: TPointF);
75 procedure PaintBox1Paint(Sender: TObject; Canvas: TCanvas);
76 private
77 { private ���� }
78 public
79 { public ���� }
80 Data: TGridData;
81 Sub: TGridData;
82 Index: integer;
83 List: TList;
84 procedure RandomSet;
85 procedure Times;
86 function CheckGame: Boolean;
87 end;
88
89 var
90 Form1: TForm1;
91
92 implementation
93
94 {$R *.fmx}
95
96 procedure TForm1.Button1Click(Sender: TObject);
97 var
98 s: TGridLog;
99 i: integer;
100 begin
101 dec(Index);
102 Data.Clear;
103 for i := 0 to Index do
104 begin
105 s := List.Items[i];
106 Data.IncData(s.X, s.Y);
107 end;
108 if Index = -1 then
109 Button1.Enabled := false;
110 if Index < List.Count - 1 then
111 Button2.Enabled := true;
112 Times;
113 PaintBox1.Repaint;
114 Label1.Visible := CheckGame;
115 end;
116
117 procedure TForm1.Button1Tap(Sender: TObject; const Point: TPointF);
118 begin
119 Button1Click(Sender);
120 end;
121
122 procedure TForm1.Button2Click(Sender: TObject);
123 var
124 s: TGridLog;
125 i: integer;
126 begin
127 inc(Index);
128 Data.Clear;
129 for i := 0 to Index do
130 begin
131 s := List.Items[i];
132 Data.IncData(s.X, s.Y);
133 end;
134 Button1.Enabled := true;
135 if Index = List.Count - 1 then
136 Button2.Enabled := false;
137 Times;
138 DoPaint(Canvas, ClientRect);
139 Invalidate;
140 Label1.Visible := CheckGame;
141 end;
142
143 procedure TForm1.Button2Tap(Sender: TObject; const Point: TPointF);
144 begin
145 Button2Click(Sender);
146 end;
147
148 procedure TForm1.Button3Click(Sender: TObject);
149 var
150 s: TGridLog;
151 i: integer;
152 begin
153 Label1.Visible := false;
154 Data.Clear;
155 Button1.Enabled := false;
156 Button2.Enabled := false;
157 RandomSet;
158 DoPaint(Canvas, ClientRect);
159 Invalidate;
160 for i := 0 to List.Count - 1 do
161 begin
162 s := List.Items[i];
163 s.Free;
164 end;
165 List.Clear;
166 Index := -1;
167 Times;
168 end;
169
170 procedure TForm1.Button3Tap(Sender: TObject; const Point: TPointF);
171 begin
172 Button3Click(Sender);
173 end;
174
175 procedure TForm1.Button4Click(Sender: TObject);
176 begin
177 Close;
178 end;
179
180 procedure TForm1.Button4Tap(Sender: TObject; const Point: TPointF);
181 begin
182 Button4Click(Sender);
183 end;
184
185 procedure TForm1.Button5Click(Sender: TObject);
186 begin
187 Data.Clear;
188 Index := -1;
189 Button1.Enabled := false;
190 if List.Count > 0 then
191 Button2.Enabled := true;
192 Times;
193 DoPaint(Canvas, ClientRect);
194 Invalidate;
195 end;
196
197 procedure TForm1.Button5Tap(Sender: TObject; const Point: TPointF);
198 begin
199 Button5Click(Sender);
200 end;
201
202 function TForm1.CheckGame: Boolean;
203 var
204 i: integer;
205 j: integer;
206 begin
207 for i := 0 to 2 do
208 for j := 0 to 2 do
209 if Data[i, j].Color <> Sub[i, j].Color then
210 begin
211 result := false;
212 Exit;
213 end;
214 result := true;
215 end;
216
217 procedure TForm1.FormCreate(Sender: TObject);
218 begin
219 Data := TGridData.Create;
220 Sub := TGridData.Create;
221 {$IFDEF MSWINDOWS}
222 Data.Size := 32;
223 Sub.Size := 16;
224 {$ELSE}
225 Data.Size := 96;
226 Sub.Size := 64;
227 {$ENDIF}
228 Sub.Protect := true;
229 Sub.Left := Data.Size * 4 + Sub.Size;
230 Label2.Position.X := PaintBox1.Position.X + Sub.Left;
231 Label2.Position.Y := PaintBox1.Position.Y + Sub.Size * 4;
232 List := TList.Create;
233 Index := -1;
234 Button3Click(Sender);
235 end;
236
237 procedure TForm1.FormDestroy(Sender: TObject);
238 var
239 i: integer;
240 s: TGridLog;
241 begin
242 Data.Free;
243 Sub.Free;
244 for i := 0 to List.Count - 1 do
245 begin
246 s := List.Items[i];
247 s.Free;
248 end;
249 List.Free;
250 end;
251
252 procedure TForm1.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
253 Shift: TShiftState; X, Y: Single);
254 var
255 i, j: Single;
256 s: TGridLog;
257 m, n, k: integer;
258 begin
259 i := X - Data.Left;
260 j := Y - Data.Top;
261 if (i > 0) and (i < Data.Size * 3) and (j > 0) and (j < Data.Size * 3) then
262 begin
263 m := Trunc(i / Data.Size);
264 n := Trunc(j / Data.Size);
265 inc(Index);
266 for k := List.Count - 1 downto Index do
267 begin
268 s := List.Items[k];
269 s.Free;
270 List.Delete(k);
271 end;
272 List.Add(TGridLog.Create(m, n));
273 Data.Temp:=Index;
274 Data.IncData(m, n);
275 PaintBox1.Repaint;
276 Button1.Enabled := true;
277 Button2.Enabled := false;
278 Times;
279 Label1.Visible := CheckGame;
280 end;
281 end;
282
283 procedure TForm1.PaintBox1Paint(Sender: TObject; Canvas: TCanvas);
284 var
285 i, j: integer;
286 s: TPointF;
287 begin
288 for i := 0 to 2 do
289 for j := 0 to 2 do
290 begin
291 s := PointF(Data.Left + i * Data.Size,Data.Top + j * Data.Size);
292 Canvas.Fill.Color := Data[i, j].Color;
293 Canvas.FillEllipse(RectF(s.X, s.Y, s.X + Data.Size, s.Y + Data.Size),
294 Data.Size);
295 s := PointF(Sub.Left + i * Sub.Size, Sub.Top + j * Sub.Size);
296 Canvas.Fill.Color := Sub[i, j].Color;
297 Canvas.FillEllipse(RectF(s.X, s.Y, s.X + Sub.Size, s.Y + Sub.Size),
298 Sub.Size);
299 end;
300 end;
301
302 procedure TForm1.RandomSet;
303 var
304 i: integer;
305 begin
306 Randomize;
307 Sub.Clear;
308 for i := 0 to Random(10) do
309 Sub.IncData(Random(3), Random(3));
310 end;
311
312 procedure TForm1.Times;
313 begin
314 Label2.Text := Format('%d / %d',[Data.Count,Sub.Count]);
315 end;
316
317 { TGridData }
318
319 constructor TGridData.Create;
320 var
321 i: integer;
322 j: integer;
323 s: TData;
324 begin
325 inherited;
326 for i := 0 to 2 do
327 for j := 0 to 2 do
328 begin
329 s := TData.Create;
330 s.Color := claBlack;
331 Strings[i, j] := s;
332 end;
333 Dummy := TData.Create;
334 end;
335
336 destructor TGridData.Destroy;
337 var
338 i: integer;
339 j: integer;
340 begin
341 for i := 0 to 2 do
342 for j := 0 to 2 do
343 Strings[i, j].Free;
344 Dummy.Free;
345 inherited;
346 end;
347
348 function TGridData.GetStrings(X, Y: integer): TData;
349 begin
350 if (X >= 0) and (X <= 2) and (Y >= 0) and (Y <= 2) then
351 begin
352 result := FStrings[X, Y];
353 end
354 else
355 begin
356 result := Dummy;
357 end;
358 end;
359
360 procedure TGridData.IncData(X, Y: integer);
361 var
362 s: TColorSet;
363 procedure Color(Value: TAlphaColor);
364 var
365 i: integer;
366 j: integer;
367 begin
368 for i := -1 to 1 do
369 for j := -1 to 1 do
370 Strings[X + i, Y + j].Color := Value;
371 end;
372
373 begin
374 if Strings[X, Y] = Dummy then
375 Exit;
376 s := Strings[X, Y].ColorSet;
377 case Temp mod 3 of
378 0:
379 begin
380 if csRed in s then
381 begin
382 if Protect = true then
383 Exit;
384 s := s - [csRed];
385 dec(Count);
386 end
387 else
388 begin
389 s := s + [csRed];
390 inc(Count);
391 end;
392 Color(claRed);
393 end;
394 1:
395 begin
396 if csBlue in s then
397 begin
398 if Protect = true then
399 Exit;
400 s := s - [csBlue];
401 dec(Count);
402 end
403 else
404 begin
405 s := s + [csBlue];
406 inc(Count);
407 end;
408 Color(claBlue);
409 end;
410 2:
411 begin
412 if csYellow in s then
413 begin
414 if Protect = true then
415 Exit;
416 s := s - [csYellow];
417 dec(Count);
418 end
419 else
420 begin
421 s := s + [csYellow];
422 inc(Count);
423 end;
424 Color(claYellow);
425 end;
426 end;
427 inc(Temp);
428 Strings[X, Y].ColorSet := s;
429 end;
430
431 procedure TGridData.SetStrings(X, Y: integer; const Value: TData);
432 begin
433 if (X >= 0) and (X <= 2) and (Y >= 0) and (Y <= 2) then
434 FStrings[X, Y] := Value;
435 end;
436
437 procedure TGridData.Clear;
438 var
439 i: integer;
440 j: integer;
441 s: TData;
442 begin
443 Count := 0;
444 Temp:=0;
445 for i := 0 to 2 do
446 for j := 0 to 2 do
447 begin
448 s := Strings[i, j];
449 s.Color := claBlack;
450 s.ColorSet := [];
451 end;
452 end;
453
454 { TData }
455
456 procedure TData.SetColor(const Value: TAlphaColor);
457 begin
458 if Value = claBlack then
459 FColor := claBlack;
460 if FColor = claRed then
461 begin
462 if Value = claRed then
463 FColor := claBlack;
464 if Value = claBlue then
465 FColor := claDarkviolet;
466 if Value = claYellow then
467 FColor := claBrown;
468 end
469 else if FColor = claBlue then
470 begin
471 if Value = claRed then
472 FColor := claDarkviolet;
473 if Value = claBlue then
474 FColor := claBlack;
475 if Value = claYellow then
476 FColor := claGreen;
477 end
478 else if FColor = claYellow then
479 begin
480 if Value = claRed then
481 FColor := claBrown;
482 if Value = claBlue then
483 FColor := claGreen;
484 if Value = claYellow then
485 FColor := claBlack;
486 end
487 else if FColor = claDarkviolet then
488 begin
489 if Value = claRed then
490 FColor := claBlue;
491 if Value = claBlue then
492 FColor := claRed;
493 if Value = claYellow then
494 FColor := claWhite;
495 end
496 else if FColor = claBrown then
497 begin
498 if Value = claRed then
499 FColor := claYellow;
500 if Value = claBlue then
501 FColor := claWhite;
502 if Value = claYellow then
503 FColor := claRed;
504 end
505 else if FColor = claGreen then
506 begin
507 if Value = claRed then
508 FColor := claWhite;
509 if Value = claBlue then
510 FColor := claYellow;
511 if Value = claYellow then
512 FColor := claBlue;
513 end
514 else if FColor = claWhite then
515 begin
516 if Value = claRed then
517 FColor := claGreen;
518 if Value = claBlue then
519 FColor := claBrown;
520 if Value = claYellow then
521 FColor := claDarkviolet;
522 end
523 else if FColor = claBlack then
524 begin
525 if Value = claRed then
526 FColor := claRed;
527 if Value = claBlue then
528 FColor := claBlue;
529 if Value = claYellow then
530 FColor := claYellow;
531 end;
532 end;
533
534 { TGridLog }
535
536 constructor TGridLog.Create(X, Y: integer);
537 begin
538 inherited Create;
539 Self.X := X;
540 Self.Y := Y;
541 end;
542
543 end.

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