Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /Unit1.pas

Parent Directory Parent Directory | Revision Log Revision Log


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

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