Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /Unit1.pas

Parent Directory Parent Directory | Revision Log Revision Log


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

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