Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /Unit1.pas

Parent Directory Parent Directory | Revision Log Revision Log


Revision 32 - (hide annotations) (download) (as text)
Sun Aug 16 07:03:42 2015 UTC (8 years, 6 months ago) by yamat0jp
File MIME type: text/x-pascal
File size: 17135 byte(s)
{Application.}ProccesMessageを呼び過ぎないように気をつけました。
1 yamat0jp 5 unit Unit1;
2 yamat0jp 1
3     interface
4    
5     uses
6 yamat0jp 5 System.SysUtils, System.Types, System.UITypes, System.Classes,
7     System.Variants,
8     FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Menus,
9     System.Math, FMX.Objects, FMX.StdCtrls;
10 yamat0jp 1
11     const
12     Count = 8;
13    
14     type
15 yamat0jp 14 TStoneType = (stNone, stWhite, stBlack, stError, stEffect);
16 yamat0jp 1
17 yamat0jp 14 TEffectData = record
18     X, Y: integer;
19     Left, Top: integer;
20     end;
21    
22 yamat0jp 3 TGridData = array [0 .. Count - 1] of array [0 .. Count - 1] of TStoneType;
23 yamat0jp 1
24 yamat0jp 30 TPlayer = class(TObject)
25 yamat0jp 1 private
26     FAuto: Boolean;
27 yamat0jp 4 FStone: TStoneType;
28 yamat0jp 1 public
29     property Auto: Boolean read FAuto write FAuto;
30 yamat0jp 4 property Stone: TStoneType read FStone write FStone;
31 yamat0jp 1 end;
32    
33 yamat0jp 30 TStoneGrid = class(TObject)
34 yamat0jp 1 private
35     FStrings: TGridData;
36 yamat0jp 7 FBuffer: array [0 .. Count * Count - 4] of TGridData;
37 yamat0jp 1 FTurnNumber: integer;
38     FTurnIndex: integer;
39 yamat0jp 9 FActive: Boolean;
40 yamat0jp 24 FList: TList;
41 yamat0jp 20 FEffectStone: TStoneType;
42 yamat0jp 14 FIndex_X: integer;
43     FIndex_Y: integer;
44 yamat0jp 28 FGameOver: Boolean;
45 yamat0jp 1 function GetStrings(X, Y: integer): TStoneType;
46     procedure SetStrings(X, Y: integer; const Value: TStoneType);
47     procedure SetTurnNumber(const Value: integer);
48 yamat0jp 28 function GetActive: Boolean;
49     procedure SetActive(const Value: Boolean);
50 yamat0jp 1 public
51 yamat0jp 14 constructor Create;
52     destructor Destroy; override;
53 yamat0jp 1 procedure Clear;
54 yamat0jp 31 function CalScore(Stone: TStoneType; X, Y: integer; out Score: integer): Boolean;
55 yamat0jp 10 function CanSetStone(Stone: TStoneType; X, Y: integer; Reverse: Boolean;
56 yamat0jp 7 const Visible: Boolean = false): Boolean;
57 yamat0jp 26 function NextStone(Stone: TStoneType; var Pos: TPoint): Boolean;
58 yamat0jp 9 procedure Start;
59     procedure Restart;
60     procedure Pause;
61 yamat0jp 14 function ListExecute: Boolean;
62 yamat0jp 28 procedure GameOver;
63 yamat0jp 14 procedure Paint(Canvas: TCanvas);
64     procedure ImageCount(X, Y: integer);
65 yamat0jp 28 function AddScore(X, Y: integer; const NG: array of TPoint): integer;
66 yamat0jp 3 property Strings[X, Y: integer]: TStoneType read GetStrings
67     write SetStrings; default;
68 yamat0jp 1 property TurnNumber: integer read FTurnNumber write SetTurnNumber;
69 yamat0jp 28 property Active: Boolean read GetActive write SetActive;
70 yamat0jp 1 end;
71    
72     TForm1 = class(TForm)
73     Timer1: TTimer;
74     MainMenu1: TMainMenu;
75 yamat0jp 5 MenuItem1: TMenuItem;
76     MenuItem2: TMenuItem;
77     MenuItem3: TMenuItem;
78     MenuItem4: TMenuItem;
79     MenuItem5: TMenuItem;
80     MenuItem6: TMenuItem;
81     MenuItem7: TMenuItem;
82     PaintBox1: TPaintBox;
83 yamat0jp 7 MenuItem8: TMenuItem;
84     MenuItem9: TMenuItem;
85     MenuItem10: TMenuItem;
86     MenuItem11: TMenuItem;
87     MenuItem12: TMenuItem;
88 yamat0jp 14 Timer2: TTimer;
89     Image1: TImage;
90     Image2: TImage;
91     Image3: TImage;
92     Image4: TImage;
93 yamat0jp 15 Image5: TImage;
94 yamat0jp 1 procedure FormCreate(Sender: TObject);
95     procedure FormDestroy(Sender: TObject);
96     procedure Timer1Timer(Sender: TObject);
97     procedure FormResize(Sender: TObject);
98 yamat0jp 5 procedure MenuItem4Click(Sender: TObject);
99     procedure MenuItem2Click(Sender: TObject);
100 yamat0jp 7 procedure PaintBox1Tap(Sender: TObject; const Point: TPointF);
101     procedure PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
102 yamat0jp 5 Shift: TShiftState; X, Y: Single);
103     procedure PaintBox1Paint(Sender: TObject; Canvas: TCanvas);
104     procedure MenuItem6Click(Sender: TObject);
105 yamat0jp 7 procedure PaintBox1Resize(Sender: TObject);
106     procedure MenuItem8Click(Sender: TObject);
107     procedure MenuItem10Click(Sender: TObject);
108     procedure MenuItem11Click(Sender: TObject);
109 yamat0jp 14 procedure Timer2Timer(Sender: TObject);
110 yamat0jp 1 private
111 yamat0jp 5 { Private ���� }
112 yamat0jp 1 StoneGrid: TStoneGrid;
113     Index: TPlayer;
114     Size: integer;
115     procedure CompStone;
116     procedure GameStart;
117     procedure ChangePlayer;
118     public
119 yamat0jp 5 { Public ���� }
120 yamat0jp 1 end;
121    
122     var
123     Player1: TPlayer;
124     Player2: TPlayer;
125    
126     Form1: TForm1;
127    
128     implementation
129    
130 yamat0jp 5 {$R *.fmx}
131 yamat0jp 7 {$R *.Windows.fmx MSWINDOWS}
132 yamat0jp 30 {$R *.XLgXhdpiTb.fmx ANDROID}
133 yamat0jp 1 { TStoneGrid }
134    
135 yamat0jp 28 function TStoneGrid.AddScore(X, Y: integer; const NG: array of TPoint): integer;
136     var
137     s: TPoint;
138     begin
139     result := 0;
140     for s in NG do
141     if (X = s.X) and (Y = s.Y) then
142     begin
143     result := 10;
144     break;
145     end;
146     end;
147    
148 yamat0jp 31 function TStoneGrid.CalScore(Stone: TStoneType; X, Y: integer; out Score: integer): Boolean;
149 yamat0jp 1 var
150     i, j: integer;
151 yamat0jp 31 const
152     wast: array [0 .. 11] of TPoint = ((X: 1; Y: 0), (X: 6; Y: 0), (X: 0;
153     Y: 1), (X: 1; Y: 1), (X: 6; Y: 1), (X: 7; Y: 1), (X: 0; Y: 6), (X: 1; Y: 6),
154     (X: 6; Y: 6), (X: 7; Y: 6), (X: 1; Y: 7), (X: 6; Y: 7));
155     worth: array [0 .. 3] of TPoint = ((X: 0; Y: 0), (X: 7; Y: 0), (X: 0;
156     Y: 7), (X: 7; Y: 7));
157 yamat0jp 1 begin
158 yamat0jp 10 if CanSetStone(Stone, X, Y, true) = true then
159 yamat0jp 1 begin
160 yamat0jp 31 Score := 0;
161     result:=true;
162 yamat0jp 30 if FTurnIndex < 50 then
163 yamat0jp 31 inc(Score, AddScore(X, Y, wast));
164     dec(Score, AddScore(X, Y, worth));
165 yamat0jp 20 case Stone of
166 yamat0jp 23 stBlack:
167     Stone := stWhite;
168     stWhite:
169     Stone := stBlack;
170 yamat0jp 20 end;
171 yamat0jp 3 for i := 0 to Count - 1 do
172     for j := 0 to Count - 1 do
173 yamat0jp 10 if CanSetStone(Stone, i, j, false) = true then
174 yamat0jp 28 begin
175 yamat0jp 31 inc(Score);
176     inc(Score, AddScore(i, j, worth));
177 yamat0jp 28 end;
178 yamat0jp 27 end
179     else
180 yamat0jp 31 result := false;
181 yamat0jp 25 FStrings := FBuffer[FTurnIndex];
182 yamat0jp 1 end;
183    
184 yamat0jp 10 function TStoneGrid.CanSetStone(Stone: TStoneType; X, Y: integer;
185 yamat0jp 7 Reverse: Boolean; const Visible: Boolean): Boolean;
186 yamat0jp 1 var
187 yamat0jp 14 i: integer;
188 yamat0jp 4 p: Boolean;
189 yamat0jp 14 q: ^TEffectData;
190 yamat0jp 4 procedure Method(m, n: integer);
191 yamat0jp 3 var
192 yamat0jp 4 s: TStoneType;
193 yamat0jp 32 j: integer;
194     k: Integer;
195 yamat0jp 1 begin
196 yamat0jp 4 if p = false then
197     Exit;
198     i := 1;
199 yamat0jp 3 while true do
200 yamat0jp 4 begin
201     s := GetStrings(X + m * i, Y + n * i);
202 yamat0jp 19 if s = stEffect then
203 yamat0jp 23 s := FEffectStone;
204 yamat0jp 4 if (s = stNone) or (s = stError) then
205     break
206 yamat0jp 10 else if s = Stone then
207 yamat0jp 4 if i > 1 then
208     begin
209 yamat0jp 15 if (result = false) and (Reverse = true) then
210     SetStrings(X, Y, Stone);
211 yamat0jp 4 result := true;
212     if Reverse = true then
213 yamat0jp 1 begin
214 yamat0jp 32 Form1.PaintBox1.Repaint;
215 yamat0jp 4 for j := 1 to i - 1 do
216 yamat0jp 7 begin
217 yamat0jp 14 if Visible = true then
218     begin
219 yamat0jp 23 FEffectStone := Stone;
220 yamat0jp 14 New(q);
221     q^.Left := X + m * j;
222     q^.Top := Y + n * j;
223     q^.X := 0;
224     q^.Y := 0;
225 yamat0jp 24 FList.Add(q);
226 yamat0jp 14 SetStrings(q^.Left, q^.Top, stEffect);
227 yamat0jp 32 for k := 1 to 10 do
228 yamat0jp 15 begin
229 yamat0jp 32 Sleep(15);
230 yamat0jp 15 Application.ProcessMessages;
231     end;
232 yamat0jp 14 end
233     else
234     SetStrings(X + m * j, Y + n * j, Stone);
235 yamat0jp 7 end;
236 yamat0jp 4 break;
237 yamat0jp 3 end
238     else
239 yamat0jp 1 begin
240 yamat0jp 4 p := false;
241 yamat0jp 3 break;
242 yamat0jp 4 end;
243     end
244     else
245     break
246 yamat0jp 3 else
247 yamat0jp 4 inc(i);
248     end;
249 yamat0jp 3 end;
250    
251     begin
252 yamat0jp 17 result := false;
253 yamat0jp 14 p := true;
254     if GetStrings(X, Y) = stNone then
255 yamat0jp 9 begin
256 yamat0jp 14 Method(-1, -1);
257     Method(-1, 0);
258     Method(-1, 1);
259     Method(0, -1);
260     Method(0, 1);
261     Method(1, -1);
262     Method(1, 0);
263     Method(1, 1);
264 yamat0jp 9 end;
265 yamat0jp 1 end;
266    
267     procedure TStoneGrid.Clear;
268     var
269     i, j: integer;
270     begin
271 yamat0jp 24 for i := 0 to FList.Count - 1 do
272     Dispose(FList[i]);
273     FList.Clear;
274 yamat0jp 3 for i := 0 to Count - 1 do
275     for j := 0 to Count - 1 do
276     Strings[i, j] := stNone;
277     Strings[3, 3] := stBlack;
278     Strings[4, 4] := stBlack;
279     Strings[4, 3] := stWhite;
280     Strings[3, 4] := stWhite;
281 yamat0jp 7 FTurnNumber := 0;
282     FTurnIndex := 0;
283 yamat0jp 10 FBuffer[0] := FStrings;
284 yamat0jp 1 end;
285    
286 yamat0jp 14 constructor TStoneGrid.Create;
287     begin
288     inherited;
289 yamat0jp 24 FList := TList.Create;
290 yamat0jp 14 end;
291    
292     destructor TStoneGrid.Destroy;
293     var
294     i: integer;
295     begin
296 yamat0jp 24 for i := 0 to FList.Count - 1 do
297     Dispose(FList[i]);
298     FList.Free;
299 yamat0jp 14 inherited;
300     end;
301    
302 yamat0jp 28 procedure TStoneGrid.GameOver;
303     begin
304     FGameOver := true;
305     FActive := false;
306     end;
307    
308     function TStoneGrid.GetActive: Boolean;
309     begin
310     if (FActive = true) and (FList.Count = 0) then
311     result := true
312     else
313     result := false;
314     end;
315    
316 yamat0jp 1 function TStoneGrid.GetStrings(X, Y: integer): TStoneType;
317     begin
318 yamat0jp 3 if (X >= 0) and (X < Count) and (Y >= 0) and (Y < Count) then
319 yamat0jp 4 result := FStrings[X, Y]
320 yamat0jp 3 else
321     result := stError;
322 yamat0jp 1 end;
323    
324 yamat0jp 14 procedure TStoneGrid.ImageCount(X, Y: integer);
325     begin
326     FIndex_X := X;
327     FIndex_Y := Y;
328     end;
329    
330     function TStoneGrid.ListExecute: Boolean;
331     var
332     p: ^TEffectData;
333     i: integer;
334     begin
335 yamat0jp 24 if FList.Count = 0 then
336 yamat0jp 14 result := false
337     else
338     begin
339 yamat0jp 24 for i := 0 to FList.Count - 1 do
340 yamat0jp 14 begin
341 yamat0jp 24 p := FList[i];
342 yamat0jp 14 if p^.X < FIndex_X - 1 then
343     p^.X := p^.X + 1
344     else if p^.Y < FIndex_Y - 1 then
345     begin
346     p^.X := 0;
347     p^.Y := p^.Y + 1;
348     end
349     else
350     begin
351 yamat0jp 25 SetStrings(p^.Left, p^.Top, FEffectStone);
352 yamat0jp 14 Dispose(p);
353 yamat0jp 24 FList[i] := nil;
354 yamat0jp 14 end;
355     end;
356 yamat0jp 24 for i := FList.Count - 1 downto 0 do
357     if FList[i] = nil then
358     FList.Delete(i);
359     if FList.Count = 0 then
360 yamat0jp 14 begin
361     inc(FTurnIndex);
362     inc(FTurnNumber);
363     FBuffer[FTurnIndex] := FStrings;
364 yamat0jp 31 Form1.PaintBox1.Repaint;
365     Form1.ChangePlayer;
366 yamat0jp 29 if FGameOver = false then
367 yamat0jp 31 FActive := true
368 yamat0jp 14 end;
369     result := true;
370     end;
371     end;
372    
373 yamat0jp 26 function TStoneGrid.NextStone(Stone: TStoneType; var Pos: TPoint): Boolean;
374 yamat0jp 1 var
375     i, j, m, n: integer;
376     begin
377 yamat0jp 31 result:=false;
378     n:=0;
379 yamat0jp 3 for i := 0 to Count - 1 do
380     for j := 0 to Count - 1 do
381 yamat0jp 31 if (CalScore(Stone, i, j, m) = true) and ((result = false)or(m < n)) then
382 yamat0jp 1 begin
383 yamat0jp 31 if result = false then
384     result:=true;
385     n:=m;
386 yamat0jp 26 Pos := Point(i, j);
387 yamat0jp 1 end;
388     end;
389    
390 yamat0jp 14 procedure TStoneGrid.Paint(Canvas: TCanvas);
391     var
392     i: integer;
393     k, m, n: integer;
394     s: TBitmap;
395     p: ^TEffectData;
396     begin
397     m := Form1.Image3.Bitmap.Width;
398     n := Form1.Image3.Bitmap.Height;
399 yamat0jp 15 k := Form1.Size;
400 yamat0jp 24 for i := 0 to FList.Count - 1 do
401 yamat0jp 14 begin
402 yamat0jp 24 p := FList[i];
403 yamat0jp 25 if FEffectStone = stBlack then
404 yamat0jp 14 s := Form1.Image1.Bitmap
405     else
406     s := Form1.Image2.Bitmap;
407     Canvas.DrawBitmap(s, RectF(p^.X * m, p^.Y * n, (p^.X + 1) * m,
408     (p^.Y + 1) * n), RectF(p^.Left * k, p^.Top * k, (p^.Left + 1) * k,
409     (p^.Top + 1) * k), 1);
410     end;
411     end;
412    
413 yamat0jp 9 procedure TStoneGrid.Pause;
414     begin
415 yamat0jp 25 FActive := false;
416 yamat0jp 9 end;
417    
418     procedure TStoneGrid.Restart;
419     begin
420 yamat0jp 31 FActive := true;
421 yamat0jp 28 FGameOver := false;
422 yamat0jp 25 FTurnIndex := FTurnNumber;
423 yamat0jp 9 end;
424    
425 yamat0jp 28 procedure TStoneGrid.SetActive(const Value: Boolean);
426     begin
427 yamat0jp 31 if (FGameOver = false) or (Value = false) then
428 yamat0jp 28 FActive := Value;
429     end;
430    
431 yamat0jp 1 procedure TStoneGrid.SetStrings(X, Y: integer; const Value: TStoneType);
432     begin
433 yamat0jp 3 if (X >= 0) and (X < Count) and (Y >= 0) and (Y < Count) then
434     FStrings[X, Y] := Value;
435 yamat0jp 1 end;
436    
437     procedure TStoneGrid.SetTurnNumber(const Value: integer);
438     begin
439     if Value > FTurnIndex then
440 yamat0jp 4 FTurnNumber := FTurnIndex
441 yamat0jp 12 else if Value < 0 then
442     FTurnNumber := 0
443 yamat0jp 3 else
444     FTurnNumber := Value;
445     FStrings := FBuffer[FTurnNumber];
446 yamat0jp 1 end;
447    
448 yamat0jp 9 procedure TStoneGrid.Start;
449     begin
450 yamat0jp 29 Clear;
451 yamat0jp 28 FActive := true;
452     FGameOver := false;
453 yamat0jp 9 end;
454    
455 yamat0jp 1 { TForm1 }
456    
457     procedure TForm1.ChangePlayer;
458     var
459     i, j, m, n: integer;
460     s: string;
461     procedure Main;
462     begin
463     if Index = Player1 then
464 yamat0jp 17 begin
465     Index := Player2;
466     s := '������������';
467     end
468 yamat0jp 3 else
469 yamat0jp 17 begin
470 yamat0jp 3 Index := Player1;
471 yamat0jp 17 s := '������������';
472     end;
473 yamat0jp 1 end;
474     function Execute: Boolean;
475     var
476     i, j: integer;
477     begin
478 yamat0jp 18 for i := 0 to Count - 1 do
479     for j := 0 to Count - 1 do
480     if StoneGrid.CanSetStone(Index.Stone, i, j, false) = true then
481     begin
482     result := true;
483     Exit;
484     end;
485 yamat0jp 3 result := false;
486 yamat0jp 1 end;
487 yamat0jp 3
488 yamat0jp 1 begin
489 yamat0jp 3 Main;
490 yamat0jp 1 if Execute = false then
491     begin
492 yamat0jp 3 Main;
493 yamat0jp 1 if Execute = false then
494     begin
495 yamat0jp 3 m := 0;
496     n := 0;
497     for i := 0 to Count - 1 do
498     for j := 0 to Count - 1 do
499     case StoneGrid[i, j] of
500     stBlack:
501     inc(m);
502     stWhite:
503     inc(n);
504 yamat0jp 1 end;
505 yamat0jp 17 Caption := s;
506 yamat0jp 1 if m > n then
507 yamat0jp 4 s := 'Player1 Win:' + #13#10
508 yamat0jp 3 else if m < n then
509 yamat0jp 4 s := 'Player2 Win:' + #13#10
510 yamat0jp 3 else
511     s := 'Draw:' + #13#10;
512 yamat0jp 28 StoneGrid.GameOver;
513 yamat0jp 31 Showmessage(s + '(Player1) ' + m.ToString+ #13#10 + '(Player2) ' +
514     n.ToString);
515 yamat0jp 17 end
516     else
517     Caption := s;
518     end
519     else
520     Caption := s;
521 yamat0jp 1 end;
522    
523     procedure TForm1.CompStone;
524     var
525     s: TPoint;
526     begin
527 yamat0jp 28 StoneGrid.Active := false;
528 yamat0jp 31 if StoneGrid.NextStone(Index.Stone, s) = true then
529     begin
530     StoneGrid.CanSetStone(Index.Stone, s.X, s.Y, true, true);
531     PaintBox1.Repaint;
532     end
533     else
534     ChangePlayer;
535 yamat0jp 1 end;
536    
537     procedure TForm1.GameStart;
538     begin
539 yamat0jp 21 Index := Player1;
540 yamat0jp 9 StoneGrid.Start;
541 yamat0jp 5 PaintBox1.Repaint;
542 yamat0jp 17 Caption := '�������n������';
543 yamat0jp 1 end;
544    
545 yamat0jp 7 procedure TForm1.MenuItem10Click(Sender: TObject);
546     begin
547 yamat0jp 9 StoneGrid.Restart;
548 yamat0jp 7 end;
549    
550     procedure TForm1.MenuItem11Click(Sender: TObject);
551 yamat0jp 17 var
552     i: integer;
553 yamat0jp 7 begin
554     with StoneGrid do
555 yamat0jp 17 begin
556     i := TurnNumber;
557 yamat0jp 7 if Sender = MenuItem11 then
558     TurnNumber := TurnNumber + 1
559     else
560     TurnNumber := TurnNumber - 1;
561 yamat0jp 17 if (i = TurnNumber) then
562     Exit
563     else
564     Pause;
565     end;
566 yamat0jp 14 PaintBox1.Repaint;
567 yamat0jp 12 ChangePlayer;
568 yamat0jp 7 end;
569    
570 yamat0jp 5 procedure TForm1.MenuItem2Click(Sender: TObject);
571 yamat0jp 1 begin
572 yamat0jp 28 Timer1.Enabled := false;
573     Timer2.Enabled := false;
574 yamat0jp 3 GameStart;
575 yamat0jp 28 Timer1.Enabled := true;
576     Timer2.Enabled := true;
577 yamat0jp 1 end;
578    
579 yamat0jp 5 procedure TForm1.MenuItem4Click(Sender: TObject);
580 yamat0jp 1 begin
581 yamat0jp 5 Close;
582 yamat0jp 1 end;
583    
584 yamat0jp 5 procedure TForm1.MenuItem6Click(Sender: TObject);
585     begin
586 yamat0jp 7 Player1.Auto := MenuItem6.IsChecked;
587     Player2.Auto := MenuItem7.IsChecked;
588 yamat0jp 5 end;
589    
590 yamat0jp 7 procedure TForm1.MenuItem8Click(Sender: TObject);
591     begin
592 yamat0jp 9 StoneGrid.Pause;
593 yamat0jp 7 end;
594    
595 yamat0jp 5 procedure TForm1.PaintBox1Paint(Sender: TObject; Canvas: TCanvas);
596 yamat0jp 1 var
597     i, j: integer;
598     begin
599 yamat0jp 18 if StoneGrid.Active = false then
600     StoneGrid.Paint(Canvas);
601 yamat0jp 17 for i := 0 to Count - 1 do
602 yamat0jp 1 begin
603 yamat0jp 17 for j := 0 to Count - 1 do
604 yamat0jp 1 begin
605 yamat0jp 3 case StoneGrid.Strings[i, j] of
606     stWhite:
607 yamat0jp 14 Canvas.DrawBitmap(Image4.Bitmap, RectF(0, 0, Image4.Bitmap.Width,
608     Image4.Bitmap.Height), RectF(i * Size, j * Size, (i + 1) * Size,
609 yamat0jp 7 (j + 1) * Size), 1);
610 yamat0jp 3 stBlack:
611 yamat0jp 14 Canvas.DrawBitmap(Image3.Bitmap, RectF(0, 0, Image3.Bitmap.Width,
612     Image3.Bitmap.Height), RectF(i * Size, j * Size, (i + 1) * Size,
613     (j + 1) * Size), 1);
614 yamat0jp 15 stEffect:
615     continue;
616 yamat0jp 14 else
617 yamat0jp 15 Canvas.DrawBitmap(Image5.Bitmap, RectF(0, 0, Image5.Bitmap.Width,
618     Image5.Bitmap.Height), RectF(i * Size, j * Size, (i + 1) * Size,
619     (j + 1) * Size), 1);
620 yamat0jp 1 end;
621 yamat0jp 15 Canvas.DrawLine(PointF(0, j * Size), PointF(Count * Size, j * Size), 1);
622 yamat0jp 1 end;
623 yamat0jp 15 Canvas.DrawLine(PointF(i * Size, 0), PointF(i * Size, Size * Count), 1);
624 yamat0jp 1 end;
625 yamat0jp 17 Canvas.DrawLine(PointF(Count * Size, 0),
626     PointF(Count * Size, Count * Size), 1);
627     Canvas.DrawLine(PointF(0, Count * Size),
628     PointF(Count * Size, Count * Size), 1);
629 yamat0jp 1 end;
630    
631 yamat0jp 7 procedure TForm1.PaintBox1Resize(Sender: TObject);
632     begin
633     Size := Min(ClientWidth, ClientHeight) div Count;
634     end;
635    
636 yamat0jp 5 procedure TForm1.FormCreate(Sender: TObject);
637 yamat0jp 1 begin
638 yamat0jp 31 ClientWidth := 50 * Count;
639     ClientHeight := 50 * Count;
640 yamat0jp 5 StoneGrid := TStoneGrid.Create;
641 yamat0jp 14 StoneGrid.ImageCount(Form1.Image1.Bitmap.Width div Form1.Image3.Bitmap.Width,
642     Form1.Image1.Bitmap.Height div Form1.Image3.Bitmap.Height);
643 yamat0jp 5 Player1 := TPlayer.Create;
644     Player2 := TPlayer.Create;
645     Player1.Stone := stBlack;
646     Player2.Stone := stWhite;
647     Player2.Auto := true;
648     with PaintBox1.Canvas do
649 yamat0jp 1 begin
650 yamat0jp 5 StrokeDash := TStrokeDash.Solid;
651     Stroke.Color := TAlphaColors.Black;
652     StrokeThickness := 3;
653 yamat0jp 1 end;
654 yamat0jp 7 PaintBox1Resize(Sender);
655 yamat0jp 5 GameStart;
656 yamat0jp 1 end;
657    
658 yamat0jp 5 procedure TForm1.FormDestroy(Sender: TObject);
659     begin
660     StoneGrid.Free;
661     Player1.Free;
662     Player2.Free;
663     end;
664    
665 yamat0jp 7 procedure TForm1.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
666 yamat0jp 5 Shift: TShiftState; X, Y: Single);
667     begin
668 yamat0jp 7 PaintBox1Tap(Sender, PointF(X, Y));
669 yamat0jp 5 end;
670    
671 yamat0jp 1 procedure TForm1.Timer1Timer(Sender: TObject);
672     begin
673 yamat0jp 10 if (StoneGrid.Active = true) and (Index.Auto = true) then
674 yamat0jp 3 CompStone;
675 yamat0jp 1 end;
676    
677 yamat0jp 14 procedure TForm1.Timer2Timer(Sender: TObject);
678     begin
679 yamat0jp 23 if (StoneGrid.Active = false) and (StoneGrid.ListExecute = true) then
680 yamat0jp 14 PaintBox1.Repaint;
681     end;
682    
683 yamat0jp 1 procedure TForm1.FormResize(Sender: TObject);
684     begin
685 yamat0jp 3 Size := Min(ClientWidth, ClientHeight) div Count;
686 yamat0jp 5 PaintTo(Canvas);
687 yamat0jp 1 end;
688    
689 yamat0jp 7 procedure TForm1.PaintBox1Tap(Sender: TObject; const Point: TPointF);
690 yamat0jp 1 begin
691 yamat0jp 11 if Index.Auto = false then
692     begin
693 yamat0jp 10 MenuItem10Click(Sender);
694 yamat0jp 28 StoneGrid.Active := false;
695 yamat0jp 10 if StoneGrid.CanSetStone(Index.Stone, Floor(Point.X / Size),
696 yamat0jp 7 Floor(Point.Y / Size), true, true) = true then
697 yamat0jp 5 PaintBox1.Repaint;
698 yamat0jp 28 StoneGrid.Active := true;
699 yamat0jp 5 end;
700 yamat0jp 1 end;
701    
702     end.

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