Develop and Download Open Source Software

Browse Subversion Repository

Diff of /Unit1.pas

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 11 by yamat0jp, Mon Jul 13 11:09:42 2015 UTC revision 35 by yamat0jp, Tue Aug 25 06:02:25 2015 UTC
# Line 4  interface Line 4  interface
4    
5  uses  uses
6    System.SysUtils, System.Types, System.UITypes, System.Classes,    System.SysUtils, System.Types, System.UITypes, System.Classes,
7    System.Variants,    System.Variants, Generics.Collections,
8    FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Menus,    FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Menus,
9    System.Math, FMX.Objects, FMX.StdCtrls;    System.Math, FMX.Objects, FMX.StdCtrls;
10    
11  const  const
12    Count = 8;    bmp_count = 8;
13    
14  type  type
15    TStoneType = (stNone, stWhite, stBlack, stError);    TStoneType = (stNone, stWhite, stBlack, stError, stEffect);
16    
17    TGridData = array [0 .. Count - 1] of array [0 .. Count - 1] of TStoneType;    TEffectData = record
18        X, Y: integer;
19        Left, Top: integer;
20      end;
21    
22      TGridData = array [0 .. bmp_count - 1] of array [0 .. bmp_count - 1]
23        of TStoneType;
24    
25    TPlayer = class    TPlayer = class(TObject)
26    private    private
27      FAuto: Boolean;      FAuto: Boolean;
28      FStone: TStoneType;      FStone: TStoneType;
# Line 25  type Line 31  type
31      property Stone: TStoneType read FStone write FStone;      property Stone: TStoneType read FStone write FStone;
32    end;    end;
33    
34    TStoneGrid = class    TStoneGrid = class(TObject)
35    private    private
36      FStrings: TGridData;      FStrings: TGridData;
37      FBuffer: array [0 .. Count * Count - 4] of TGridData;      FBuffer: array [0 .. bmp_count * bmp_count - 4] of TGridData;
38      FTurnNumber: integer;      FTurnNumber: integer;
39      FTurnIndex: integer;      FTurnIndex: integer;
40      FActive: Boolean;      FActive: Boolean;
41        FList: TList<TEffectData>;
42        FEffectStone: TStoneType;
43        FIndex_X: integer;
44        FIndex_Y: integer;
45        FGameOver: Boolean;
46      function GetStrings(X, Y: integer): TStoneType;      function GetStrings(X, Y: integer): TStoneType;
47      procedure SetStrings(X, Y: integer; const Value: TStoneType);      procedure SetStrings(X, Y: integer; const Value: TStoneType);
48      procedure SetTurnNumber(const Value: integer);      procedure SetTurnNumber(const Value: integer);
49        function GetActive: Boolean;
50        procedure SetActive(const Value: Boolean);
51    public    public
52        constructor Create;
53        destructor Destroy; override;
54      procedure Clear;      procedure Clear;
55      function CalScore(Stone: TStoneType; X, Y: integer): integer;      function CalScore(Stone: TStoneType; X, Y: integer;
56          out Score: integer): Boolean;
57      function CanSetStone(Stone: TStoneType; X, Y: integer; Reverse: Boolean;      function CanSetStone(Stone: TStoneType; X, Y: integer; Reverse: Boolean;
58        const Visible: Boolean = false): Boolean;        const Visible: Boolean = false): Boolean;
59      function NextStone(Stone: TStoneType): TPoint;      function NextStone(Stone: TStoneType; var Pos: TPoint): Boolean;
60      procedure Start;      procedure Start;
61      procedure Restart;      procedure Restart;
62      procedure Pause;      procedure Pause;
63        function ListExecute: Boolean;
64        procedure GameOver;
65        procedure Paint(Canvas: TCanvas);
66        procedure ImageCount(X, Y: integer);
67        function AddScore(X, Y: integer; const NG: array of TPoint): integer;
68      property Strings[X, Y: integer]: TStoneType read GetStrings      property Strings[X, Y: integer]: TStoneType read GetStrings
69        write SetStrings; default;        write SetStrings; default;
70      property TurnNumber: integer read FTurnNumber write SetTurnNumber;      property TurnNumber: integer read FTurnNumber write SetTurnNumber;
71      property Active: Boolean read FActive;      property Active: Boolean read GetActive write SetActive;
72    end;    end;
73    
74    TForm1 = class(TForm)    TForm1 = class(TForm)
# Line 66  type Line 87  type
87      MenuItem10: TMenuItem;      MenuItem10: TMenuItem;
88      MenuItem11: TMenuItem;      MenuItem11: TMenuItem;
89      MenuItem12: TMenuItem;      MenuItem12: TMenuItem;
90        Timer2: TTimer;
91        Image1: TImage;
92        Image2: TImage;
93        Image3: TImage;
94        MenuItem13: TMenuItem;
95        MenuItem14: TMenuItem;
96        MenuItem15: TMenuItem;
97      procedure FormCreate(Sender: TObject);      procedure FormCreate(Sender: TObject);
98      procedure FormDestroy(Sender: TObject);      procedure FormDestroy(Sender: TObject);
99      procedure Timer1Timer(Sender: TObject);      procedure Timer1Timer(Sender: TObject);
# Line 81  type Line 109  type
109      procedure MenuItem8Click(Sender: TObject);      procedure MenuItem8Click(Sender: TObject);
110      procedure MenuItem10Click(Sender: TObject);      procedure MenuItem10Click(Sender: TObject);
111      procedure MenuItem11Click(Sender: TObject);      procedure MenuItem11Click(Sender: TObject);
112        procedure Timer2Timer(Sender: TObject);
113    private    private
114      { Private 宣言 }      { Private 宣言 }
115      StoneGrid: TStoneGrid;      StoneGrid: TStoneGrid;
# Line 103  implementation Line 132  implementation
132    
133  {$R *.fmx}  {$R *.fmx}
134  {$R *.Windows.fmx MSWINDOWS}  {$R *.Windows.fmx MSWINDOWS}
135    {$R *.XLgXhdpiTb.fmx ANDROID}
136  { TStoneGrid }  { TStoneGrid }
137    
138  function TStoneGrid.CalScore(Stone: TStoneType; X, Y: integer): integer;  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    function TStoneGrid.CalScore(Stone: TStoneType; X, Y: integer;
152      out Score: integer): Boolean;
153  var  var
154    i, j: integer;    i, j: integer;
155      loop: integer;
156    const
157      waste: array [1 .. 12] of TPoint = ((X: 1; Y: 0), (X: 6; Y: 0), (X: 0; Y: 1),
158        (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    label Last;
163      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      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              Easy;
198            end;
199            FStrings := FBuffer[FTurnIndex + loop];
200          end;
201      end;
202    
203  begin  begin
204    if CanSetStone(Stone, X, Y, true) = true then    if CanSetStone(Stone, X, Y, true) = true then
205    begin    begin
206      if Stone = stBlack then      Score := 0;
207        Stone := stWhite      result := true;
208      else      if FTurnIndex < 50 then
209        Stone := stBlack;        inc(Score, AddScore(X, Y, waste));
210      result := 0;      dec(Score, AddScore(X, Y, worth));
211      for i := 0 to Count - 1 do      case Stone of
212        for j := 0 to Count - 1 do        stBlack:
213          if CanSetStone(Stone, i, j, false) = true then          Stone := stWhite;
214            inc(result);        stWhite:
215      FStrings := FBuffer[FTurnIndex];          Stone := stBlack;
216        end;
217        if (Form1.MenuItem14.IsChecked = true) and (FTurnIndex + 1 <= 60) then
218        begin
219          FBuffer[FTurnIndex + 1] := FStrings;
220          loop := 0;
221          Hard;
222        end;
223        Easy;
224    end    end
225    else    else
226    begin      result := false;
227      FStrings := FBuffer[FTurnIndex];    FStrings := FBuffer[FTurnIndex];
     result := -1;  
   end;  
228  end;  end;
229    
230  function TStoneGrid.CanSetStone(Stone: TStoneType; X, Y: integer;  function TStoneGrid.CanSetStone(Stone: TStoneType; X, Y: integer;
231    Reverse: Boolean; const Visible: Boolean): Boolean;    Reverse: Boolean; const Visible: Boolean): Boolean;
232  var  var
233    i, k: integer;    i: integer;
234    p: Boolean;    p: Boolean;
235    q: ^TPoint;    q: TEffectData;
   list: TList;  
236    procedure Method(m, n: integer);    procedure Method(m, n: integer);
237    var    var
238      s: TStoneType;      s: TStoneType;
239      j: integer;      j: integer;
240        k: integer;
241    begin    begin
242      if p = false then      if p = false then
243        Exit;        Exit;
# Line 147  var Line 245  var
245      while true do      while true do
246      begin      begin
247        s := GetStrings(X + m * i, Y + n * i);        s := GetStrings(X + m * i, Y + n * i);
248          if s = stEffect then
249            s := FEffectStone;
250        if (s = stNone) or (s = stError) then        if (s = stNone) or (s = stError) then
251          break          break
252        else if s = Stone then        else if s = Stone then
253          if i > 1 then          if i > 1 then
254          begin          begin
255              if (result = false) and (Reverse = true) then
256                SetStrings(X, Y, Stone);
257            result := true;            result := true;
258            if Reverse = true then            if Reverse = true then
259            begin            begin
260                Form1.PaintBox1.Repaint;
261              for j := 1 to i - 1 do              for j := 1 to i - 1 do
262              begin              begin
263                New(q);                if Visible = true then
264                q^ := Point(X + m * j, Y + n * j);                begin
265                list.Add(q);                  FEffectStone := Stone;
266                    q.Left := X + m * j;
267                    q.Top := Y + n * j;
268                    q.X := 0;
269                    q.Y := 0;
270                    FList.Add(q);
271                    SetStrings(q.Left, q.Top, stEffect);
272                    for k := 1 to 10 do
273                    begin
274                      Sleep(15);
275                      Application.ProcessMessages;
276                    end;
277                  end
278                  else
279                    SetStrings(X + m * j, Y + n * j, Stone);
280              end;              end;
281              break;              break;
282            end            end
# Line 177  var Line 294  var
294    end;    end;
295    
296  begin  begin
297    list := TList.Create;    result := false;
298    try    p := true;
299      result := false;    if GetStrings(X, Y) = stNone then
300      p := true;    begin
301      if GetStrings(X, Y) = stNone then      Method(-1, -1);
302      begin      Method(-1, 0);
303        Method(-1, -1);      Method(-1, 1);
304        Method(-1, 0);      Method(0, -1);
305        Method(-1, 1);      Method(0, 1);
306        Method(0, -1);      Method(1, -1);
307        Method(0, 1);      Method(1, 0);
308        Method(1, -1);      Method(1, 1);
       Method(1, 0);  
       Method(1, 1);  
     end;  
     if (Reverse = true) and (result = true) then  
     begin  
       SetStrings(X, Y, Stone);  
       for i := 0 to list.Count - 1 do  
       begin  
         if Visible = true then  
         begin  
           for k := 1 to 10 do  
           begin  
             Sleep(10);  
             Application.ProcessMessages;  
           end;  
           Form1.PaintBox1.Repaint;  
         end;  
         q := list[i];  
         SetStrings(q^.X, q^.Y, Stone);  
       end;  
     end;  
   finally  
     for i := 0 to list.Count - 1 do  
       Dispose(list[i]);  
     list.Free;  
   end;  
   if Visible = true then  
   begin  
     inc(FTurnIndex);  
     inc(FTurnNumber);  
     FBuffer[FTurnIndex] := FStrings;  
309    end;    end;
310  end;  end;
311    
# Line 227  procedure TStoneGrid.Clear; Line 313  procedure TStoneGrid.Clear;
313  var  var
314    i, j: integer;    i, j: integer;
315  begin  begin
316    for i := 0 to Count - 1 do    FList.Clear;
317      for j := 0 to Count - 1 do    for i := 0 to bmp_count - 1 do
318        for j := 0 to bmp_count - 1 do
319        Strings[i, j] := stNone;        Strings[i, j] := stNone;
320    Strings[3, 3] := stBlack;    Strings[3, 3] := stBlack;
321    Strings[4, 4] := stBlack;    Strings[4, 4] := stBlack;
# Line 239  begin Line 326  begin
326    FBuffer[0] := FStrings;    FBuffer[0] := FStrings;
327  end;  end;
328    
329    constructor TStoneGrid.Create;
330    begin
331      inherited;
332      FList := TList<TEffectData>.Create;
333    end;
334    
335    destructor TStoneGrid.Destroy;
336    begin
337      FList.Free;
338      inherited;
339    end;
340    
341    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  function TStoneGrid.GetStrings(X, Y: integer): TStoneType;  function TStoneGrid.GetStrings(X, Y: integer): TStoneType;
356  begin  begin
357    if (X >= 0) and (X < Count) and (Y >= 0) and (Y < Count) then    if (X >= 0) and (X < bmp_count) and (Y >= 0) and (Y < bmp_count) then
358      result := FStrings[X, Y]      result := FStrings[X, Y]
359    else    else
360      result := stError;      result := stError;
361  end;  end;
362    
363  function TStoneGrid.NextStone(Stone: TStoneType): TPoint;  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  var
371    i, j, m, n: integer;    i: integer;
372      s: TEffectData;
373  begin  begin
374    n := -1;    if FList.Count = 0 then
375    for i := 0 to Count - 1 do      result := false
376      for j := 0 to Count - 1 do    else
377      begin
378        i := 0;
379        while i < FList.Count do
380      begin      begin
381        m := CalScore(Stone, i, j);        s := FList[i];
382        if (n = -1) or ((m > -1) and (n > m)) then        if s.X < FIndex_X - 1 then
383            s.X := s.X + 1
384          else if s.Y < FIndex_Y - 1 then
385        begin        begin
386          n := m;          s.X := 0;
387          result := Point(i, j);          s.Y := s.Y + 1;
388          end
389          else
390          begin
391            SetStrings(s.Left, s.Top, FEffectStone);
392            FList.Delete(i);
393            inc(i);
394            continue;
395        end;        end;
396          FList[i] := s;
397          inc(i);
398      end;      end;
399    if n = -1 then      if FList.Count = 0 then
400      result := Point(-1, -1);      begin
401          inc(FTurnIndex);
402          inc(FTurnNumber);
403          FBuffer[FTurnIndex] := FStrings;
404          Form1.PaintBox1.Repaint;
405          Form1.ChangePlayer;
406          if FGameOver = false then
407            FActive := true
408        end;
409        result := true;
410      end;
411    end;
412    
413    function TStoneGrid.NextStone(Stone: TStoneType; var Pos: TPoint): Boolean;
414    var
415      i, j, m, n: integer;
416    begin
417      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          begin
424            if result = false then
425              result := true;
426            n := m;
427            Pos := Point(i, j);
428          end;
429    end;
430    
431    procedure TStoneGrid.Paint(Canvas: TCanvas);
432    var
433      k: integer;
434      s: TBitmap;
435      p: TEffectData;
436    begin
437      k := Form1.Size;
438      if FEffectStone = stBlack then
439        s := Form1.Image1.Bitmap
440      else
441        s := Form1.Image2.Bitmap;
442      for p in FList do
443      begin
444        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      end;
448  end;  end;
449    
450  procedure TStoneGrid.Pause;  procedure TStoneGrid.Pause;
# Line 274  end; Line 455  end;
455  procedure TStoneGrid.Restart;  procedure TStoneGrid.Restart;
456  begin  begin
457    FActive := true;    FActive := true;
458      FGameOver := false;
459    FTurnIndex := FTurnNumber;    FTurnIndex := FTurnNumber;
460  end;  end;
461    
462    procedure TStoneGrid.SetActive(const Value: Boolean);
463    begin
464      if (FGameOver = false) or (Value = false) then
465        FActive := Value;
466    end;
467    
468  procedure TStoneGrid.SetStrings(X, Y: integer; const Value: TStoneType);  procedure TStoneGrid.SetStrings(X, Y: integer; const Value: TStoneType);
469  begin  begin
470    if (X >= 0) and (X < Count) and (Y >= 0) and (Y < Count) then    if (X >= 0) and (X < bmp_count) and (Y >= 0) and (Y < bmp_count) then
471      FStrings[X, Y] := Value;      FStrings[X, Y] := Value;
472  end;  end;
473    
# Line 287  procedure TStoneGrid.SetTurnNumber(const Line 475  procedure TStoneGrid.SetTurnNumber(const
475  begin  begin
476    if Value > FTurnIndex then    if Value > FTurnIndex then
477      FTurnNumber := FTurnIndex      FTurnNumber := FTurnIndex
478      else if Value < 0 then
479        FTurnNumber := 0
480    else    else
481      FTurnNumber := Value;      FTurnNumber := Value;
   FActive := false;  
482    FStrings := FBuffer[FTurnNumber];    FStrings := FBuffer[FTurnNumber];
483  end;  end;
484    
# Line 297  procedure TStoneGrid.Start; Line 486  procedure TStoneGrid.Start;
486  begin  begin
487    Clear;    Clear;
488    FActive := true;    FActive := true;
489      FGameOver := false;
490  end;  end;
491    
492  { TForm1 }  { TForm1 }
# Line 308  var Line 498  var
498    procedure Main;    procedure Main;
499    begin    begin
500      if Index = Player1 then      if Index = Player1 then
501        Index := Player2      begin
502          Index := Player2;
503          s := '白の手番です';
504        end
505      else      else
506        begin
507        Index := Player1;        Index := Player1;
508          s := '黒の手番です';
509        end;
510    end;    end;
511    function Execute: Boolean;    function Execute: Boolean;
512    var    var
513      i, j: integer;      i, j: integer;
514    begin    begin
515      result := false;      for i := 0 to bmp_count - 1 do
516      for i := 0 to Count - 1 do        for j := 0 to bmp_count - 1 do
     begin  
       for j := 0 to Count - 1 do  
517          if StoneGrid.CanSetStone(Index.Stone, i, j, false) = true then          if StoneGrid.CanSetStone(Index.Stone, i, j, false) = true then
518          begin          begin
519            result := true;            result := true;
520            break;            Exit;
521          end;          end;
522        if result = true then      result := false;
         break;  
     end;  
523    end;    end;
524    
525  begin  begin
# Line 337  begin Line 529  begin
529      Main;      Main;
530      if Execute = false then      if Execute = false then
531      begin      begin
       StoneGrid.Pause;  
       Timer1.Enabled := false;  
532        m := 0;        m := 0;
533        n := 0;        n := 0;
534        for i := 0 to Count - 1 do        for i := 0 to bmp_count - 1 do
535          for j := 0 to Count - 1 do          for j := 0 to bmp_count - 1 do
536            case StoneGrid[i, j] of            case StoneGrid[i, j] of
537              stBlack:              stBlack:
538                inc(m);                inc(m);
539              stWhite:              stWhite:
540                inc(n);                inc(n);
541            end;            end;
542          Caption := s;
543        if m > n then        if m > n then
544          s := 'Player1 Win:' + #13#10          s := 'Player1 Win:' + #13#10
545        else if m < n then        else if m < n then
546          s := 'Player2 Win:' + #13#10          s := 'Player2 Win:' + #13#10
547        else        else
548          s := 'Draw:' + #13#10;          s := 'Draw:' + #13#10;
549        Showmessage(s + '(Player1) ' + IntToStr(m) + #13#10 + '(Player2) ' +        StoneGrid.GameOver;
550          IntToStr(n));        Showmessage(s + '(Player1) ' + m.ToString + #13#10 + '(Player2) ' +
551      end;          n.ToString);
552    end;      end
553        else
554          Caption := s;
555      end
556      else
557        Caption := s;
558  end;  end;
559    
560  procedure TForm1.CompStone;  procedure TForm1.CompStone;
561  var  var
562    s: TPoint;    s: TPoint;
563  begin  begin
564    s := StoneGrid.NextStone(Index.Stone);    StoneGrid.Active := false;
565    StoneGrid.CanSetStone(Index.Stone, s.X, s.Y, true, true);    if StoneGrid.NextStone(Index.Stone, s) = true then
566    PaintBox1.Repaint;    begin
567    ChangePlayer;      StoneGrid.CanSetStone(Index.Stone, s.X, s.Y, true, true);
568        PaintBox1.Repaint;
569      end
570      else
571        ChangePlayer;
572  end;  end;
573    
574  procedure TForm1.GameStart;  procedure TForm1.GameStart;
575  begin  begin
576      Index := Player1;
577    StoneGrid.Start;    StoneGrid.Start;
578    PaintBox1.Repaint;    PaintBox1.Repaint;
579    Index := Player1;    Caption := '黒から始めます';
   Timer1.Enabled := true;  
580  end;  end;
581    
582  procedure TForm1.MenuItem10Click(Sender: TObject);  procedure TForm1.MenuItem10Click(Sender: TObject);
583  begin  begin
584    StoneGrid.Restart;    StoneGrid.Restart;
   Timer1.Enabled := true;  
585  end;  end;
586    
587  procedure TForm1.MenuItem11Click(Sender: TObject);  procedure TForm1.MenuItem11Click(Sender: TObject);
588    var
589      i: integer;
590  begin  begin
   Timer1.Enabled := false;  
591    with StoneGrid do    with StoneGrid do
592      begin
593        i := TurnNumber;
594      if Sender = MenuItem11 then      if Sender = MenuItem11 then
595        TurnNumber := TurnNumber + 1        TurnNumber := TurnNumber + 1
596      else      else
597        TurnNumber := TurnNumber - 1;        TurnNumber := TurnNumber - 1;
598        if (i = TurnNumber) then
599          Exit
600        else
601          Pause;
602      end;
603    PaintBox1.Repaint;    PaintBox1.Repaint;
604      ChangePlayer;
605  end;  end;
606    
607  procedure TForm1.MenuItem2Click(Sender: TObject);  procedure TForm1.MenuItem2Click(Sender: TObject);
608  begin  begin
609      Timer1.Enabled := false;
610      Timer2.Enabled := false;
611    GameStart;    GameStart;
612      Timer1.Enabled := true;
613      Timer2.Enabled := true;
614  end;  end;
615    
616  procedure TForm1.MenuItem4Click(Sender: TObject);  procedure TForm1.MenuItem4Click(Sender: TObject);
# Line 410  procedure TForm1.MenuItem6Click(Sender: Line 622  procedure TForm1.MenuItem6Click(Sender:
622  begin  begin
623    Player1.Auto := MenuItem6.IsChecked;    Player1.Auto := MenuItem6.IsChecked;
624    Player2.Auto := MenuItem7.IsChecked;    Player2.Auto := MenuItem7.IsChecked;
   MenuItem10Click(Sender);  
625  end;  end;
626    
627  procedure TForm1.MenuItem8Click(Sender: TObject);  procedure TForm1.MenuItem8Click(Sender: TObject);
628  begin  begin
629    StoneGrid.Pause;    StoneGrid.Pause;
   Timer1.Enabled := false;  
630  end;  end;
631    
632  procedure TForm1.PaintBox1Paint(Sender: TObject; Canvas: TCanvas);  procedure TForm1.PaintBox1Paint(Sender: TObject; Canvas: TCanvas);
633  var  var
634    i, j: integer;    i, j: integer;
635  begin  begin
636    Canvas.Fill.Color := TAlphaColors.White;    if StoneGrid.Active = false then
637    Canvas.FillRect(RectF(0, 0, Count * Size, Count * Size), 0, 0, [], 1);      StoneGrid.Paint(Canvas);
638    for i := 0 to Count do    for i := 0 to bmp_count - 1 do
639    begin    begin
640      Canvas.DrawLine(PointF(i * Size, 0), PointF(i * Size, Size * Count), 1);      for j := 0 to bmp_count - 1 do
     for j := 0 to Count do  
641      begin      begin
       Canvas.DrawLine(PointF(0, j * Size), PointF(Count * Size, j * Size), 1);  
642        case StoneGrid.Strings[i, j] of        case StoneGrid.Strings[i, j] of
643          stWhite:          stWhite:
644            Canvas.DrawEllipse(RectF(i * Size, j * Size, (i + 1) * Size,            Canvas.DrawBitmap(Image3.Bitmap, RectF(100, 0, 150, 50),
645              (j + 1) * Size), 1);              RectF(i * Size, j * Size, (i + 1) * Size, (j + 1) * Size), 1);
646          stBlack:          stBlack:
647            begin            Canvas.DrawBitmap(Image3.Bitmap, RectF(50, 0, 100, 50),
648              Canvas.Fill.Color := TAlphaColors.Black;              RectF(i * Size, j * Size, (i + 1) * Size, (j + 1) * Size), 1);
649              Canvas.FillEllipse(RectF(i * Size, j * Size, (i + 1) * Size,          stEffect:
650                (j + 1) * Size), 1);            continue;
651            end;        else
652            Canvas.DrawBitmap(Image3.Bitmap, RectF(0, 0, 50, 50),
653              RectF(i * Size, j * Size, (i + 1) * Size, (j + 1) * Size), 1);
654        end;        end;
655          Canvas.DrawLine(PointF(0, j * Size), PointF(bmp_count * Size,
656            j * Size), 1);
657      end;      end;
658        Canvas.DrawLine(PointF(i * Size, 0), PointF(i * Size, Size * bmp_count), 1);
659    end;    end;
660      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  end;  end;
665    
666  procedure TForm1.PaintBox1Resize(Sender: TObject);  procedure TForm1.PaintBox1Resize(Sender: TObject);
667  begin  begin
668    Size := Min(ClientWidth, ClientHeight) div Count;    Size := Min(ClientWidth, ClientHeight) div bmp_count;
669  end;  end;
670    
671  procedure TForm1.FormCreate(Sender: TObject);  procedure TForm1.FormCreate(Sender: TObject);
672  begin  begin
673      ClientWidth := 400;
674      ClientHeight := 400;
675    StoneGrid := TStoneGrid.Create;    StoneGrid := TStoneGrid.Create;
676      StoneGrid.ImageCount(6, 5);
677    Player1 := TPlayer.Create;    Player1 := TPlayer.Create;
678    Player2 := TPlayer.Create;    Player2 := TPlayer.Create;
679    Player1.Stone := stBlack;    Player1.Stone := stBlack;
# Line 485  end; Line 705  end;
705  procedure TForm1.Timer1Timer(Sender: TObject);  procedure TForm1.Timer1Timer(Sender: TObject);
706  begin  begin
707    if (StoneGrid.Active = true) and (Index.Auto = true) then    if (StoneGrid.Active = true) and (Index.Auto = true) then
   begin  
     Timer1.Enabled := false;  
708      CompStone;      CompStone;
709      Timer1.Enabled := true;  end;
710    end;  
711    procedure TForm1.Timer2Timer(Sender: TObject);
712    begin
713      if (StoneGrid.Active = false) and (StoneGrid.ListExecute = true) then
714        PaintBox1.Repaint;
715  end;  end;
716    
717  procedure TForm1.FormResize(Sender: TObject);  procedure TForm1.FormResize(Sender: TObject);
718  begin  begin
719    Size := Min(ClientWidth, ClientHeight) div Count;    Size := Min(ClientWidth, ClientHeight) div bmp_count;
720    PaintTo(Canvas);    PaintTo(Canvas);
721  end;  end;
722    
# Line 503  begin Line 725  begin
725    if Index.Auto = false then    if Index.Auto = false then
726    begin    begin
727      MenuItem10Click(Sender);      MenuItem10Click(Sender);
728        StoneGrid.Active := false;
729      if StoneGrid.CanSetStone(Index.Stone, Floor(Point.X / Size),      if StoneGrid.CanSetStone(Index.Stone, Floor(Point.X / Size),
730        Floor(Point.Y / Size), true, true) = true then        Floor(Point.Y / Size), true, true) = true then
     begin  
731        PaintBox1.Repaint;        PaintBox1.Repaint;
732        ChangePlayer;      StoneGrid.Active := true;
     end;  
733    end;    end;
734  end;  end;
735    

Legend:
Removed from v.11  
changed lines
  Added in v.35

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