Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /Unit1.pas

Parent Directory Parent Directory | Revision Log Revision Log


Revision 35 - (hide annotations) (download) (as text)
Tue Aug 25 06:02:25 2015 UTC (8 years, 6 months ago) by yamat0jp
File MIME type: text/x-pascal
File size: 17709 byte(s)
本に書こうかと思ってソースコードを見直したらHardモードに入らないような設計になっていました。

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

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