Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /Unit1.pas

Parent Directory Parent Directory | Revision Log Revision Log


Revision 34 - (hide annotations) (download) (as text)
Sun Aug 23 05:26:29 2015 UTC (8 years, 7 months ago) by yamat0jp
File MIME type: text/x-pascal
File size: 17615 byte(s)
難易度Hardを付け加えました。従来より2手先読みしますが強くなっているかはわかりません。

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

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