Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /Unit1.pas

Parent Directory Parent Directory | Revision Log Revision Log


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

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