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 13 by yamat0jp, Tue Jul 14 00:24:36 2015 UTC revision 33 by yamat0jp, Wed Aug 19 14:41:09 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        Image4: TImage;
95        Image5: TImage;
96      procedure FormCreate(Sender: TObject);      procedure FormCreate(Sender: TObject);
97      procedure FormDestroy(Sender: TObject);      procedure FormDestroy(Sender: TObject);
98      procedure Timer1Timer(Sender: TObject);      procedure Timer1Timer(Sender: TObject);
# Line 81  type Line 108  type
108      procedure MenuItem8Click(Sender: TObject);      procedure MenuItem8Click(Sender: TObject);
109      procedure MenuItem10Click(Sender: TObject);      procedure MenuItem10Click(Sender: TObject);
110      procedure MenuItem11Click(Sender: TObject);      procedure MenuItem11Click(Sender: TObject);
111        procedure Timer2Timer(Sender: TObject);
112    private    private
113      { Private 宣言 }      { Private 宣言 }
114      StoneGrid: TStoneGrid;      StoneGrid: TStoneGrid;
# Line 103  implementation Line 131  implementation
131    
132  {$R *.fmx}  {$R *.fmx}
133  {$R *.Windows.fmx MSWINDOWS}  {$R *.Windows.fmx MSWINDOWS}
134    {$R *.XLgXhdpiTb.fmx ANDROID}
135  { TStoneGrid }  { TStoneGrid }
136    
137  function TStoneGrid.CalScore(Stone: TStoneType; X, Y: integer): integer;  function TStoneGrid.AddScore(X, Y: integer; const NG: array of TPoint): integer;
138    var
139      s: TPoint;
140    begin
141      result := 0;
142      for s in NG do
143        if (X = s.X) and (Y = s.Y) then
144        begin
145          result := 10;
146          break;
147        end;
148    end;
149    
150    function TStoneGrid.CalScore(Stone: TStoneType; X, Y: integer;
151      out Score: integer): Boolean;
152  var  var
153    i, j: integer;    i, j: integer;
154    const
155      wast: array [1 .. 12] of TPoint = ((X: 1; Y: 0), (X: 6; Y: 0), (X: 0; Y: 1),
156        (X: 1; Y: 1), (X: 6; Y: 1), (X: 7; Y: 1), (X: 0; Y: 6), (X: 1; Y: 6), (X: 6;
157        Y: 6), (X: 7; Y: 6), (X: 1; Y: 7), (X: 6; Y: 7));
158      worth: array [1 .. 4] of TPoint = ((X: 0; Y: 0), (X: 7; Y: 0), (X: 0; Y: 7),
159        (X: 7; Y: 7));
160  begin  begin
161    if CanSetStone(Stone, X, Y, true) = true then    if CanSetStone(Stone, X, Y, true) = true then
162    begin    begin
163      if Stone = stBlack then      Score := 0;
164        Stone := stWhite      result := true;
165      else      if FTurnIndex < 50 then
166        Stone := stBlack;        inc(Score, AddScore(X, Y, wast));
167      result := 0;      dec(Score, AddScore(X, Y, worth));
168      for i := 0 to Count - 1 do      case Stone of
169        for j := 0 to Count - 1 do        stBlack:
170            Stone := stWhite;
171          stWhite:
172            Stone := stBlack;
173        end;
174        for i := 0 to bmp_count - 1 do
175          for j := 0 to bmp_count - 1 do
176          if CanSetStone(Stone, i, j, false) = true then          if CanSetStone(Stone, i, j, false) = true then
177            inc(result);          begin
178      FStrings := FBuffer[FTurnIndex];            inc(Score);
179              inc(Score, AddScore(i, j, worth));
180            end;
181    end    end
182    else    else
183    begin      result := false;
184      FStrings := FBuffer[FTurnIndex];    FStrings := FBuffer[FTurnIndex];
     result := -1;  
   end;  
185  end;  end;
186    
187  function TStoneGrid.CanSetStone(Stone: TStoneType; X, Y: integer;  function TStoneGrid.CanSetStone(Stone: TStoneType; X, Y: integer;
188    Reverse: Boolean; const Visible: Boolean): Boolean;    Reverse: Boolean; const Visible: Boolean): Boolean;
189  var  var
190    i, k: integer;    i: integer;
191    p: Boolean;    p: Boolean;
192    q: ^TPoint;    q: TEffectData;
   list: TList;  
193    procedure Method(m, n: integer);    procedure Method(m, n: integer);
194    var    var
195      s: TStoneType;      s: TStoneType;
196      j: integer;      j: integer;
197        k: integer;
198    begin    begin
199      if p = false then      if p = false then
200        Exit;        Exit;
# Line 147  var Line 202  var
202      while true do      while true do
203      begin      begin
204        s := GetStrings(X + m * i, Y + n * i);        s := GetStrings(X + m * i, Y + n * i);
205          if s = stEffect then
206            s := FEffectStone;
207        if (s = stNone) or (s = stError) then        if (s = stNone) or (s = stError) then
208          break          break
209        else if s = Stone then        else if s = Stone then
210          if i > 1 then          if i > 1 then
211          begin          begin
212              if (result = false) and (Reverse = true) then
213                SetStrings(X, Y, Stone);
214            result := true;            result := true;
215            if Reverse = true then            if Reverse = true then
216            begin            begin
217                Form1.PaintBox1.Repaint;
218              for j := 1 to i - 1 do              for j := 1 to i - 1 do
219              begin              begin
220                New(q);                if Visible = true then
221                q^ := Point(X + m * j, Y + n * j);                begin
222                list.Add(q);                  FEffectStone := Stone;
223                    q.Left := X + m * j;
224                    q.Top := Y + n * j;
225                    q.X := 0;
226                    q.Y := 0;
227                    FList.Add(q);
228                    SetStrings(q.Left, q.Top, stEffect);
229                    for k := 1 to 10 do
230                    begin
231                      Sleep(15);
232                      Application.ProcessMessages;
233                    end;
234                  end
235                  else
236                    SetStrings(X + m * j, Y + n * j, Stone);
237              end;              end;
238              break;              break;
239            end            end
# Line 177  var Line 251  var
251    end;    end;
252    
253  begin  begin
254    list := TList.Create;    result := false;
255    try    p := true;
256      result := false;    if GetStrings(X, Y) = stNone then
257      p := true;    begin
258      if GetStrings(X, Y) = stNone then      Method(-1, -1);
259      begin      Method(-1, 0);
260        Method(-1, -1);      Method(-1, 1);
261        Method(-1, 0);      Method(0, -1);
262        Method(-1, 1);      Method(0, 1);
263        Method(0, -1);      Method(1, -1);
264        Method(0, 1);      Method(1, 0);
265        Method(1, -1);      Method(1, 1);
       Method(1, 0);  
       Method(1, 1);  
       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;  
     end;  
   finally  
     for i := 0 to list.Count - 1 do  
       Dispose(list[i]);  
     list.Free;  
   end;  
   if (Visible = true)and(result = true) then  
   begin  
     inc(FTurnIndex);  
     inc(FTurnNumber);  
     FBuffer[FTurnIndex] := FStrings;  
266    end;    end;
267  end;  end;
268    
# Line 227  procedure TStoneGrid.Clear; Line 270  procedure TStoneGrid.Clear;
270  var  var
271    i, j: integer;    i, j: integer;
272  begin  begin
273    for i := 0 to Count - 1 do    FList.Clear;
274      for j := 0 to Count - 1 do    for i := 0 to bmp_count - 1 do
275        for j := 0 to bmp_count - 1 do
276        Strings[i, j] := stNone;        Strings[i, j] := stNone;
277    Strings[3, 3] := stBlack;    Strings[3, 3] := stBlack;
278    Strings[4, 4] := stBlack;    Strings[4, 4] := stBlack;
# Line 239  begin Line 283  begin
283    FBuffer[0] := FStrings;    FBuffer[0] := FStrings;
284  end;  end;
285    
286    constructor TStoneGrid.Create;
287    begin
288      inherited;
289      FList := TList<TEffectData>.Create;
290    end;
291    
292    destructor TStoneGrid.Destroy;
293    begin
294      FList.Free;
295      inherited;
296    end;
297    
298    procedure TStoneGrid.GameOver;
299    begin
300      FGameOver := true;
301      FActive := false;
302    end;
303    
304    function TStoneGrid.GetActive: Boolean;
305    begin
306      if (FActive = true) and (FList.Count = 0) then
307        result := true
308      else
309        result := false;
310    end;
311    
312  function TStoneGrid.GetStrings(X, Y: integer): TStoneType;  function TStoneGrid.GetStrings(X, Y: integer): TStoneType;
313  begin  begin
314    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
315      result := FStrings[X, Y]      result := FStrings[X, Y]
316    else    else
317      result := stError;      result := stError;
318  end;  end;
319    
320  function TStoneGrid.NextStone(Stone: TStoneType): TPoint;  procedure TStoneGrid.ImageCount(X, Y: integer);
321    begin
322      FIndex_X := X;
323      FIndex_Y := Y;
324    end;
325    
326    function TStoneGrid.ListExecute: Boolean;
327  var  var
328    i, j, m, n: integer;    i: integer;
329      s: TEffectData;
330  begin  begin
331    n := -1;    if FList.Count = 0 then
332    for i := 0 to Count - 1 do      result := false
333      for j := 0 to Count - 1 do    else
334      begin
335        i:=0;
336        while i < FList.Count do
337      begin      begin
338        m := CalScore(Stone, i, j);        s := FList[i];
339        if (n = -1) or ((m > -1) and (n > m)) then        if s.X < FIndex_X - 1 then
340            s.X := s.X + 1
341          else if s.Y < FIndex_Y - 1 then
342        begin        begin
343          n := m;          s.X := 0;
344          result := Point(i, j);          s.Y := s.Y + 1;
345          end
346          else
347          begin
348            SetStrings(s.Left, s.Top, FEffectStone);
349            FList.Delete(i);
350            inc(i);
351            continue;
352        end;        end;
353          FList[i]:=s;
354          inc(i);
355      end;      end;
356    if n = -1 then      if FList.Count = 0 then
357      result := Point(-1, -1);      begin
358          inc(FTurnIndex);
359          inc(FTurnNumber);
360          FBuffer[FTurnIndex] := FStrings;
361          Form1.PaintBox1.Repaint;
362          Form1.ChangePlayer;
363          if FGameOver = false then
364            FActive := true
365        end;
366        result := true;
367      end;
368    end;
369    
370    function TStoneGrid.NextStone(Stone: TStoneType; var Pos: TPoint): Boolean;
371    var
372      i, j, m, n: integer;
373    begin
374      result := false;
375      n := 0;
376      for i := 0 to bmp_count - 1 do
377        for j := 0 to bmp_count - 1 do
378          if (CalScore(Stone, i, j, m) = true) and ((result = false) or (m < n))
379          then
380          begin
381            if result = false then
382              result := true;
383            n := m;
384            Pos := Point(i, j);
385          end;
386    end;
387    
388    procedure TStoneGrid.Paint(Canvas: TCanvas);
389    var
390      k, m, n: integer;
391      s: TBitmap;
392      p: TEffectData;
393    begin
394      m := Form1.Image3.Bitmap.Width;
395      n := Form1.Image3.Bitmap.Height;
396      k := Form1.Size;
397      if FEffectStone = stBlack then
398        s := Form1.Image1.Bitmap
399      else
400        s := Form1.Image2.Bitmap;
401      for p in FList do
402      begin
403        Canvas.DrawBitmap(s, RectF(p.X * m, p.Y * n, (p.X + 1) * m, (p.Y + 1) * n),
404          RectF(p.Left * k, p.Top * k, (p.Left + 1) * k, (p.Top + 1) * k), 1);
405      end;
406  end;  end;
407    
408  procedure TStoneGrid.Pause;  procedure TStoneGrid.Pause;
# Line 274  end; Line 413  end;
413  procedure TStoneGrid.Restart;  procedure TStoneGrid.Restart;
414  begin  begin
415    FActive := true;    FActive := true;
416      FGameOver := false;
417    FTurnIndex := FTurnNumber;    FTurnIndex := FTurnNumber;
418  end;  end;
419    
420    procedure TStoneGrid.SetActive(const Value: Boolean);
421    begin
422      if (FGameOver = false) or (Value = false) then
423        FActive := Value;
424    end;
425    
426  procedure TStoneGrid.SetStrings(X, Y: integer; const Value: TStoneType);  procedure TStoneGrid.SetStrings(X, Y: integer; const Value: TStoneType);
427  begin  begin
428    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
429      FStrings[X, Y] := Value;      FStrings[X, Y] := Value;
430  end;  end;
431    
# Line 291  begin Line 437  begin
437      FTurnNumber := 0      FTurnNumber := 0
438    else    else
439      FTurnNumber := Value;      FTurnNumber := Value;
   FActive := false;  
440    FStrings := FBuffer[FTurnNumber];    FStrings := FBuffer[FTurnNumber];
441  end;  end;
442    
# Line 299  procedure TStoneGrid.Start; Line 444  procedure TStoneGrid.Start;
444  begin  begin
445    Clear;    Clear;
446    FActive := true;    FActive := true;
447      FGameOver := false;
448  end;  end;
449    
450  { TForm1 }  { TForm1 }
# Line 310  var Line 456  var
456    procedure Main;    procedure Main;
457    begin    begin
458      if Index = Player1 then      if Index = Player1 then
459        Index := Player2      begin
460          Index := Player2;
461          s := '白の手番です';
462        end
463      else      else
464        begin
465        Index := Player1;        Index := Player1;
466          s := '黒の手番です';
467        end;
468    end;    end;
469    function Execute: Boolean;    function Execute: Boolean;
470    var    var
471      i, j: integer;      i, j: integer;
472    begin    begin
473      result := false;      for i := 0 to bmp_count - 1 do
474      for i := 0 to Count - 1 do        for j := 0 to bmp_count - 1 do
       for j := 0 to Count - 1 do  
475          if StoneGrid.CanSetStone(Index.Stone, i, j, false) = true then          if StoneGrid.CanSetStone(Index.Stone, i, j, false) = true then
476          begin          begin
477            result := true;            result := true;
478            Exit;            Exit;
479          end;          end;
480        result := false;
481    end;    end;
482    
483  begin  begin
# Line 335  begin Line 487  begin
487      Main;      Main;
488      if Execute = false then      if Execute = false then
489      begin      begin
       StoneGrid.Pause;  
       Timer1.Enabled := false;  
490        m := 0;        m := 0;
491        n := 0;        n := 0;
492        for i := 0 to Count - 1 do        for i := 0 to bmp_count - 1 do
493          for j := 0 to Count - 1 do          for j := 0 to bmp_count - 1 do
494            case StoneGrid[i, j] of            case StoneGrid[i, j] of
495              stBlack:              stBlack:
496                inc(m);                inc(m);
497              stWhite:              stWhite:
498                inc(n);                inc(n);
499            end;            end;
500          Caption := s;
501        if m > n then        if m > n then
502          s := 'Player1 Win:' + #13#10          s := 'Player1 Win:' + #13#10
503        else if m < n then        else if m < n then
504          s := 'Player2 Win:' + #13#10          s := 'Player2 Win:' + #13#10
505        else        else
506          s := 'Draw:' + #13#10;          s := 'Draw:' + #13#10;
507        Showmessage(s + '(Player1) ' + IntToStr(m) + #13#10 + '(Player2) ' +        StoneGrid.GameOver;
508          IntToStr(n));        Showmessage(s + '(Player1) ' + m.ToString + #13#10 + '(Player2) ' +
509      end;          n.ToString);
510    end;      end
511        else
512          Caption := s;
513      end
514      else
515        Caption := s;
516  end;  end;
517    
518  procedure TForm1.CompStone;  procedure TForm1.CompStone;
519  var  var
520    s: TPoint;    s: TPoint;
521  begin  begin
522    s := StoneGrid.NextStone(Index.Stone);    StoneGrid.Active := false;
523    StoneGrid.CanSetStone(Index.Stone, s.X, s.Y, true, true);    if StoneGrid.NextStone(Index.Stone, s) = true then
524    PaintBox1.Repaint;    begin
525    ChangePlayer;      StoneGrid.CanSetStone(Index.Stone, s.X, s.Y, true, true);
526        PaintBox1.Repaint;
527      end
528      else
529        ChangePlayer;
530  end;  end;
531    
532  procedure TForm1.GameStart;  procedure TForm1.GameStart;
533  begin  begin
534      Index := Player1;
535    StoneGrid.Start;    StoneGrid.Start;
536    PaintBox1.Repaint;    PaintBox1.Repaint;
537    Index := Player1;    Caption := '黒から始めます';
   Timer1.Enabled := true;  
538  end;  end;
539    
540  procedure TForm1.MenuItem10Click(Sender: TObject);  procedure TForm1.MenuItem10Click(Sender: TObject);
541  begin  begin
542    StoneGrid.Restart;    StoneGrid.Restart;
   Timer1.Enabled := true;  
543  end;  end;
544    
545  procedure TForm1.MenuItem11Click(Sender: TObject);  procedure TForm1.MenuItem11Click(Sender: TObject);
546    var
547      i: integer;
548  begin  begin
   Timer1.Enabled := false;  
549    with StoneGrid do    with StoneGrid do
550      begin
551        i := TurnNumber;
552      if Sender = MenuItem11 then      if Sender = MenuItem11 then
553        TurnNumber := TurnNumber + 1        TurnNumber := TurnNumber + 1
554      else      else
555        TurnNumber := TurnNumber - 1;        TurnNumber := TurnNumber - 1;
556    ChangePlayer;      if (i = TurnNumber) then
557          Exit
558        else
559          Pause;
560      end;
561    PaintBox1.Repaint;    PaintBox1.Repaint;
562      ChangePlayer;
563  end;  end;
564    
565  procedure TForm1.MenuItem2Click(Sender: TObject);  procedure TForm1.MenuItem2Click(Sender: TObject);
566  begin  begin
567      Timer1.Enabled := false;
568      Timer2.Enabled := false;
569    GameStart;    GameStart;
570      Timer1.Enabled := true;
571      Timer2.Enabled := true;
572  end;  end;
573    
574  procedure TForm1.MenuItem4Click(Sender: TObject);  procedure TForm1.MenuItem4Click(Sender: TObject);
# Line 409  procedure TForm1.MenuItem6Click(Sender: Line 580  procedure TForm1.MenuItem6Click(Sender:
580  begin  begin
581    Player1.Auto := MenuItem6.IsChecked;    Player1.Auto := MenuItem6.IsChecked;
582    Player2.Auto := MenuItem7.IsChecked;    Player2.Auto := MenuItem7.IsChecked;
   MenuItem10Click(Sender);  
583  end;  end;
584    
585  procedure TForm1.MenuItem8Click(Sender: TObject);  procedure TForm1.MenuItem8Click(Sender: TObject);
586  begin  begin
587    StoneGrid.Pause;    StoneGrid.Pause;
   Timer1.Enabled := false;  
588  end;  end;
589    
590  procedure TForm1.PaintBox1Paint(Sender: TObject; Canvas: TCanvas);  procedure TForm1.PaintBox1Paint(Sender: TObject; Canvas: TCanvas);
591  var  var
592    i, j: integer;    i, j: integer;
593  begin  begin
594    Canvas.Fill.Color := TAlphaColors.White;    if StoneGrid.Active = false then
595    Canvas.FillRect(RectF(0, 0, Count * Size, Count * Size), 0, 0, [], 1);      StoneGrid.Paint(Canvas);
596    for i := 0 to Count do    for i := 0 to bmp_count - 1 do
597    begin    begin
598      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  
599      begin      begin
       Canvas.DrawLine(PointF(0, j * Size), PointF(Count * Size, j * Size), 1);  
600        case StoneGrid.Strings[i, j] of        case StoneGrid.Strings[i, j] of
601          stWhite:          stWhite:
602            Canvas.DrawEllipse(RectF(i * Size, j * Size, (i + 1) * Size,            Canvas.DrawBitmap(Image4.Bitmap, RectF(0, 0, Image4.Bitmap.Width,
603                Image4.Bitmap.Height), RectF(i * Size, j * Size, (i + 1) * Size,
604              (j + 1) * Size), 1);              (j + 1) * Size), 1);
605          stBlack:          stBlack:
606            begin            Canvas.DrawBitmap(Image3.Bitmap, RectF(0, 0, Image3.Bitmap.Width,
607              Canvas.Fill.Color := TAlphaColors.Black;              Image3.Bitmap.Height), RectF(i * Size, j * Size, (i + 1) * Size,
608              Canvas.FillEllipse(RectF(i * Size, j * Size, (i + 1) * Size,              (j + 1) * Size), 1);
609                (j + 1) * Size), 1);          stEffect:
610            end;            continue;
611          else
612            Canvas.DrawBitmap(Image5.Bitmap, RectF(0, 0, Image5.Bitmap.Width,
613              Image5.Bitmap.Height), RectF(i * Size, j * Size, (i + 1) * Size,
614              (j + 1) * Size), 1);
615        end;        end;
616          Canvas.DrawLine(PointF(0, j * Size), PointF(bmp_count * Size,
617            j * Size), 1);
618      end;      end;
619        Canvas.DrawLine(PointF(i * Size, 0), PointF(i * Size, Size * bmp_count), 1);
620    end;    end;
621      Canvas.DrawLine(PointF(bmp_count * Size, 0), PointF(bmp_count * Size,
622        bmp_count * Size), 1);
623      Canvas.DrawLine(PointF(0, bmp_count * Size), PointF(bmp_count * Size,
624        bmp_count * Size), 1);
625  end;  end;
626    
627  procedure TForm1.PaintBox1Resize(Sender: TObject);  procedure TForm1.PaintBox1Resize(Sender: TObject);
628  begin  begin
629    Size := Min(ClientWidth, ClientHeight) div Count;    Size := Min(ClientWidth, ClientHeight) div bmp_count;
630  end;  end;
631    
632  procedure TForm1.FormCreate(Sender: TObject);  procedure TForm1.FormCreate(Sender: TObject);
633  begin  begin
634      ClientWidth := 50 * bmp_count;
635      ClientHeight := 50 * bmp_count;
636    StoneGrid := TStoneGrid.Create;    StoneGrid := TStoneGrid.Create;
637      StoneGrid.ImageCount(6, 5);
638    Player1 := TPlayer.Create;    Player1 := TPlayer.Create;
639    Player2 := TPlayer.Create;    Player2 := TPlayer.Create;
640    Player1.Stone := stBlack;    Player1.Stone := stBlack;
# Line 484  end; Line 666  end;
666  procedure TForm1.Timer1Timer(Sender: TObject);  procedure TForm1.Timer1Timer(Sender: TObject);
667  begin  begin
668    if (StoneGrid.Active = true) and (Index.Auto = true) then    if (StoneGrid.Active = true) and (Index.Auto = true) then
   begin  
     Timer1.Enabled := false;  
669      CompStone;      CompStone;
670      Timer1.Enabled := true;  end;
671    end;  
672    procedure TForm1.Timer2Timer(Sender: TObject);
673    begin
674      if (StoneGrid.Active = false) and (StoneGrid.ListExecute = true) then
675        PaintBox1.Repaint;
676  end;  end;
677    
678  procedure TForm1.FormResize(Sender: TObject);  procedure TForm1.FormResize(Sender: TObject);
679  begin  begin
680    Size := Min(ClientWidth, ClientHeight) div Count;    Size := Min(ClientWidth, ClientHeight) div bmp_count;
681    PaintTo(Canvas);    PaintTo(Canvas);
682  end;  end;
683    
# Line 502  begin Line 686  begin
686    if Index.Auto = false then    if Index.Auto = false then
687    begin    begin
688      MenuItem10Click(Sender);      MenuItem10Click(Sender);
689        StoneGrid.Active := false;
690      if StoneGrid.CanSetStone(Index.Stone, Floor(Point.X / Size),      if StoneGrid.CanSetStone(Index.Stone, Floor(Point.X / Size),
691        Floor(Point.Y / Size), true, true) = true then        Floor(Point.Y / Size), true, true) = true then
     begin  
692        PaintBox1.Repaint;        PaintBox1.Repaint;
693        ChangePlayer;      StoneGrid.Active := true;
     end;  
694    end;    end;
695  end;  end;
696    

Legend:
Removed from v.13  
changed lines
  Added in v.33

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