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 25 by yamat0jp, Mon Jul 20 00:50:13 2015 UTC revision 34 by yamat0jp, Sun Aug 23 05:26:29 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, stEffect);    TStoneType = (stNone, stWhite, stBlack, stError, stEffect);
# Line 19  type Line 19  type
19      Left, Top: integer;      Left, Top: integer;
20    end;    end;
21    
22    TGridData = array [0 .. Count - 1] of array [0 .. Count - 1] of TStoneType;    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 30  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;      FList: TList<TEffectData>;
42      FEffectStone: TStoneType;      FEffectStone: TStoneType;
     FBool: Boolean;  
     FTerminated: Boolean;  
43      FIndex_X: integer;      FIndex_X: integer;
44      FIndex_Y: integer;      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;      constructor Create;
53      destructor Destroy; override;      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;      function ListExecute: Boolean;
64        procedure GameOver;
65      procedure Paint(Canvas: TCanvas);      procedure Paint(Canvas: TCanvas);
66      procedure ImageCount(X, Y: integer);      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 86  type Line 91  type
91      Image1: TImage;      Image1: TImage;
92      Image2: TImage;      Image2: TImage;
93      Image3: TImage;      Image3: TImage;
94      Image4: TImage;      MenuItem13: TMenuItem;
95      Image5: TImage;      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 104  type Line 110  type
110      procedure MenuItem10Click(Sender: TObject);      procedure MenuItem10Click(Sender: TObject);
111      procedure MenuItem11Click(Sender: TObject);      procedure MenuItem11Click(Sender: TObject);
112      procedure Timer2Timer(Sender: TObject);      procedure Timer2Timer(Sender: TObject);
     procedure FormDeactivate(Sender: TObject);  
     procedure FormActivate(Sender: TObject);  
113    private    private
114      { Private 宣言 }      { Private 宣言 }
115      StoneGrid: TStoneGrid;      StoneGrid: TStoneGrid;
# Line 128  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 Hard;
164      var
165        m, n: integer;
166      begin
167        if loop > 2 then
168          Exit;
169        inc(loop);
170        for m := 0 to bmp_count - 1 do
171          for n := 0 to bmp_count - 1 do
172          begin
173            if CanSetStone(Stone, m, n, true) = true then
174            begin
175              inc(Score, AddScore(m, n, worth));
176              if FTurnIndex + 1 < 50 then
177                dec(Score, AddScore(m, n, waste));
178              case Stone of
179                stBlack:
180                  Stone := stWhite;
181                stWhite:
182                  Stone := stBlack;
183              end;
184              Hard;
185            end;
186            FStrings := FBuffer[FTurnIndex + 1];
187          end;
188      end;
189    
190  begin  begin
   result:=0;  
191    if CanSetStone(Stone, X, Y, true) = true then    if CanSetStone(Stone, X, Y, true) = true then
192    begin    begin
193      if Stone = stEffect then      Score := 0;
194        Stone:=FEffectStone;      result := true;
195        if FTurnIndex < 50 then
196          inc(Score, AddScore(X, Y, waste));
197        dec(Score, AddScore(X, Y, worth));
198      case Stone of      case Stone of
199        stBlack:        stBlack:
200          Stone := stWhite;          Stone := stWhite;
201        stWhite:        stWhite:
202          Stone := stBlack;          Stone := stBlack;
       else  
         Exit;  
203      end;      end;
204      for i := 0 to Count - 1 do      if (Form1.MenuItem14.IsChecked = true) and (FTurnIndex + 1 >= 60) then
205        for j := 0 to Count - 1 do      begin
206          FBuffer[FTurnIndex + 1] := FStrings;
207          loop := 0;
208          Hard;
209        end;
210        for i := 0 to bmp_count - 1 do
211          for j := 0 to bmp_count - 1 do
212          if CanSetStone(Stone, i, j, false) = true then          if CanSetStone(Stone, i, j, false) = true then
213            inc(result);          begin
214    end;            inc(Score);
215              inc(Score, AddScore(i, j, worth));
216            end;
217      end
218      else
219        result := false;
220    FStrings := FBuffer[FTurnIndex];    FStrings := FBuffer[FTurnIndex];
221  end;  end;
222    
# Line 160  function TStoneGrid.CanSetStone(Stone: T Line 225  function TStoneGrid.CanSetStone(Stone: T
225  var  var
226    i: integer;    i: integer;
227    p: Boolean;    p: Boolean;
228    q: ^TEffectData;    q: TEffectData;
229    procedure Method(m, n: integer);    procedure Method(m, n: integer);
230    var    var
231      s: TStoneType;      s: TStoneType;
232      j, k: integer;      j: integer;
233        k: integer;
234    begin    begin
235      if p = false then      if p = false then
236        Exit;        Exit;
# Line 184  var Line 250  var
250            result := true;            result := true;
251            if Reverse = true then            if Reverse = true then
252            begin            begin
253                Form1.PaintBox1.Repaint;
254              for j := 1 to i - 1 do              for j := 1 to i - 1 do
255              begin              begin
               Form1.PaintBox1.Repaint;  
256                if Visible = true then                if Visible = true then
257                begin                begin
258                  FEffectStone := Stone;                  FEffectStone := Stone;
259                  New(q);                  q.Left := X + m * j;
260                  q^.Left := X + m * j;                  q.Top := Y + n * j;
261                  q^.Top := Y + n * j;                  q.X := 0;
262                  q^.X := 0;                  q.Y := 0;
                 q^.Y := 0;  
263                  FList.Add(q);                  FList.Add(q);
264                  SetStrings(q^.Left, q^.Top, stEffect);                  SetStrings(q.Left, q.Top, stEffect);
265                  for k := 1 to 100 do                  for k := 1 to 10 do
266                  begin                  begin
267                    Sleep(1);                    Sleep(15);
268                    Application.ProcessMessages;                    Application.ProcessMessages;
269                  end;                  end;
270                end                end
# Line 223  var Line 288  var
288    
289  begin  begin
290    result := false;    result := false;
   if Visible = true then  
   begin  
     FBool := FActive;  
     FActive := false;  
   end;  
291    p := true;    p := true;
292    if GetStrings(X, Y) = stNone then    if GetStrings(X, Y) = stNone then
293    begin    begin
# Line 246  procedure TStoneGrid.Clear; Line 306  procedure TStoneGrid.Clear;
306  var  var
307    i, j: integer;    i, j: integer;
308  begin  begin
   for i := 0 to FList.Count - 1 do  
     Dispose(FList[i]);  
309    FList.Clear;    FList.Clear;
310    for i := 0 to Count - 1 do    for i := 0 to bmp_count - 1 do
311      for j := 0 to Count - 1 do      for j := 0 to bmp_count - 1 do
312        Strings[i, j] := stNone;        Strings[i, j] := stNone;
313    Strings[3, 3] := stBlack;    Strings[3, 3] := stBlack;
314    Strings[4, 4] := stBlack;    Strings[4, 4] := stBlack;
# Line 264  end; Line 322  end;
322  constructor TStoneGrid.Create;  constructor TStoneGrid.Create;
323  begin  begin
324    inherited;    inherited;
325    FList := TList.Create;    FList := TList<TEffectData>.Create;
326  end;  end;
327    
328  destructor TStoneGrid.Destroy;  destructor TStoneGrid.Destroy;
 var  
   i: integer;  
329  begin  begin
   for i := 0 to FList.Count - 1 do  
     Dispose(FList[i]);  
330    FList.Free;    FList.Free;
331    inherited;    inherited;
332  end;  end;
333    
334    procedure TStoneGrid.GameOver;
335    begin
336      FGameOver := true;
337      FActive := false;
338    end;
339    
340    function TStoneGrid.GetActive: Boolean;
341    begin
342      if (FActive = true) and (FList.Count = 0) then
343        result := true
344      else
345        result := false;
346    end;
347    
348  function TStoneGrid.GetStrings(X, Y: integer): TStoneType;  function TStoneGrid.GetStrings(X, Y: integer): TStoneType;
349  begin  begin
350    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
351      result := FStrings[X, Y]      result := FStrings[X, Y]
352    else    else
353      result := stError;      result := stError;
# Line 293  end; Line 361  end;
361    
362  function TStoneGrid.ListExecute: Boolean;  function TStoneGrid.ListExecute: Boolean;
363  var  var
   p: ^TEffectData;  
364    i: integer;    i: integer;
365      s: TEffectData;
366  begin  begin
367    if FList.Count = 0 then    if FList.Count = 0 then
368      result := false      result := false
369    else    else
370    begin    begin
371      for i := 0 to FList.Count - 1 do      i := 0;
372        while i < FList.Count do
373      begin      begin
374        p := FList[i];        s := FList[i];
375        if p^.X < FIndex_X - 1 then        if s.X < FIndex_X - 1 then
376          p^.X := p^.X + 1          s.X := s.X + 1
377        else if p^.Y < FIndex_Y - 1 then        else if s.Y < FIndex_Y - 1 then
378        begin        begin
379          p^.X := 0;          s.X := 0;
380          p^.Y := p^.Y + 1;          s.Y := s.Y + 1;
381        end        end
382        else        else
383        begin        begin
384          SetStrings(p^.Left, p^.Top, FEffectStone);          SetStrings(s.Left, s.Top, FEffectStone);
385          Dispose(p);          FList.Delete(i);
386          FList[i] := nil;          inc(i);
387            continue;
388        end;        end;
389          FList[i] := s;
390          inc(i);
391      end;      end;
     for i := FList.Count - 1 downto 0 do  
       if FList[i] = nil then  
         FList.Delete(i);  
392      if FList.Count = 0 then      if FList.Count = 0 then
393      begin      begin
       if FTerminated = true then  
         FActive := false  
       else  
         FActive := FBool;  
394        inc(FTurnIndex);        inc(FTurnIndex);
395        inc(FTurnNumber);        inc(FTurnNumber);
396        FBuffer[FTurnIndex] := FStrings;        FBuffer[FTurnIndex] := FStrings;
397          Form1.PaintBox1.Repaint;
398          Form1.ChangePlayer;
399          if FGameOver = false then
400            FActive := true
401      end;      end;
402      result := true;      result := true;
403    end;    end;
404  end;  end;
405    
406  function TStoneGrid.NextStone(Stone: TStoneType): TPoint;  function TStoneGrid.NextStone(Stone: TStoneType; var Pos: TPoint): Boolean;
407  var  var
408    i, j, m, n: integer;    i, j, m, n: integer;
409  begin  begin
410      result := false;
411    n := 0;    n := 0;
412    for i := 0 to Count - 1 do    for i := 0 to bmp_count - 1 do
413      for j := 0 to Count - 1 do      for j := 0 to bmp_count - 1 do
414      begin        if (CalScore(Stone, i, j, m) = true) and ((result = false) or (m < n))
415        m := CalScore(Stone, i, j);        then
       if ((n = 0)and(m > 0)) or ((0 < m) and (m < n)) then  
416        begin        begin
417            if result = false then
418              result := true;
419          n := m;          n := m;
420          result := Point(i, j);          Pos := Point(i, j);
421        end;        end;
     end;  
   if n = 0 then  
     result := Point(-1, -1);  
422  end;  end;
423    
424  procedure TStoneGrid.Paint(Canvas: TCanvas);  procedure TStoneGrid.Paint(Canvas: TCanvas);
425  var  var
426    i: integer;    k: integer;
   k, m, n: integer;  
427    s: TBitmap;    s: TBitmap;
428    p: ^TEffectData;    p: TEffectData;
429  begin  begin
   m := Form1.Image3.Bitmap.Width;  
   n := Form1.Image3.Bitmap.Height;  
430    k := Form1.Size;    k := Form1.Size;
431    for i := 0 to FList.Count - 1 do    if FEffectStone = stBlack then
432        s := Form1.Image1.Bitmap
433      else
434        s := Form1.Image2.Bitmap;
435      for p in FList do
436    begin    begin
437      p := FList[i];      Canvas.DrawBitmap(s, RectF(p.X * 50, p.Y * 50, (p.X + 1) * 50,
438      if FEffectStone = stBlack then        (p.Y + 1) * 50), RectF(p.Left * k, p.Top * k, (p.Left + 1) * k,
439        s := Form1.Image1.Bitmap        (p.Top + 1) * k), 1);
     else  
       s := Form1.Image2.Bitmap;  
     Canvas.DrawBitmap(s, RectF(p^.X * m, p^.Y * n, (p^.X + 1) * m,  
       (p^.Y + 1) * n), RectF(p^.Left * k, p^.Top * k, (p^.Left + 1) * k,  
       (p^.Top + 1) * k), 1);  
440    end;    end;
441  end;  end;
442    
443  procedure TStoneGrid.Pause;  procedure TStoneGrid.Pause;
444  begin  begin
445    FActive := false;    FActive := false;
   FTerminated := true;  
446  end;  end;
447    
448  procedure TStoneGrid.Restart;  procedure TStoneGrid.Restart;
449  begin  begin
450    FActive := true;    FActive := true;
451      FGameOver := false;
452    FTurnIndex := FTurnNumber;    FTurnIndex := FTurnNumber;
453    FTerminated := false;  end;
454    
455    procedure TStoneGrid.SetActive(const Value: Boolean);
456    begin
457      if (FGameOver = false) or (Value = false) then
458        FActive := Value;
459  end;  end;
460    
461  procedure TStoneGrid.SetStrings(X, Y: integer; const Value: TStoneType);  procedure TStoneGrid.SetStrings(X, Y: integer; const Value: TStoneType);
462  begin  begin
463    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
464      FStrings[X, Y] := Value;      FStrings[X, Y] := Value;
465  end;  end;
466    
# Line 409  end; Line 478  end;
478  procedure TStoneGrid.Start;  procedure TStoneGrid.Start;
479  begin  begin
480    Clear;    Clear;
   FTerminated := false;  
481    FActive := true;    FActive := true;
482      FGameOver := false;
483  end;  end;
484    
485  { TForm1 }  { TForm1 }
# Line 436  var Line 505  var
505    var    var
506      i, j: integer;      i, j: integer;
507    begin    begin
508      for i := 0 to Count - 1 do      for i := 0 to bmp_count - 1 do
509        for j := 0 to Count - 1 do        for j := 0 to bmp_count - 1 do
510          if StoneGrid.CanSetStone(Index.Stone, i, j, false) = true then          if StoneGrid.CanSetStone(Index.Stone, i, j, false) = true then
511          begin          begin
512            result := true;            result := true;
# Line 453  begin Line 522  begin
522      Main;      Main;
523      if Execute = false then      if Execute = false then
524      begin      begin
       StoneGrid.Pause;  
525        m := 0;        m := 0;
526        n := 0;        n := 0;
527        for i := 0 to Count - 1 do        for i := 0 to bmp_count - 1 do
528          for j := 0 to Count - 1 do          for j := 0 to bmp_count - 1 do
529            case StoneGrid[i, j] of            case StoneGrid[i, j] of
530              stBlack:              stBlack:
531                inc(m);                inc(m);
# Line 471  begin Line 539  begin
539          s := 'Player2 Win:' + #13#10          s := 'Player2 Win:' + #13#10
540        else        else
541          s := 'Draw:' + #13#10;          s := 'Draw:' + #13#10;
542        Showmessage(s + '(Player1) ' + IntToStr(m) + #13#10 + '(Player2) ' +        StoneGrid.GameOver;
543          IntToStr(n));        Showmessage(s + '(Player1) ' + m.ToString + #13#10 + '(Player2) ' +
544            n.ToString);
545      end      end
546      else      else
547        Caption := s;        Caption := s;
# Line 485  procedure TForm1.CompStone; Line 554  procedure TForm1.CompStone;
554  var  var
555    s: TPoint;    s: TPoint;
556  begin  begin
557    s := StoneGrid.NextStone(Index.Stone);    StoneGrid.Active := false;
558    StoneGrid.CanSetStone(Index.Stone, s.X, s.Y, true, true);    if StoneGrid.NextStone(Index.Stone, s) = true then
559    PaintBox1.Repaint;    begin
560    ChangePlayer;      StoneGrid.CanSetStone(Index.Stone, s.X, s.Y, true, true);
561        PaintBox1.Repaint;
562      end
563      else
564        ChangePlayer;
565  end;  end;
566    
567  procedure TForm1.GameStart;  procedure TForm1.GameStart;
568  begin  begin
   Timer1.Enabled:=false;  
569    Index := Player1;    Index := Player1;
570    StoneGrid.Start;    StoneGrid.Start;
571    PaintBox1.Repaint;    PaintBox1.Repaint;
572    Caption := '黒から始めます';    Caption := '黒から始めます';
   Timer1.Enabled:=true;  
573  end;  end;
574    
575  procedure TForm1.MenuItem10Click(Sender: TObject);  procedure TForm1.MenuItem10Click(Sender: TObject);
# Line 528  end; Line 599  end;
599    
600  procedure TForm1.MenuItem2Click(Sender: TObject);  procedure TForm1.MenuItem2Click(Sender: TObject);
601  begin  begin
602      Timer1.Enabled := false;
603      Timer2.Enabled := false;
604    GameStart;    GameStart;
605      Timer1.Enabled := true;
606      Timer2.Enabled := true;
607  end;  end;
608    
609  procedure TForm1.MenuItem4Click(Sender: TObject);  procedure TForm1.MenuItem4Click(Sender: TObject);
# Line 553  var Line 628  var
628  begin  begin
629    if StoneGrid.Active = false then    if StoneGrid.Active = false then
630      StoneGrid.Paint(Canvas);      StoneGrid.Paint(Canvas);
631    for i := 0 to Count - 1 do    for i := 0 to bmp_count - 1 do
632    begin    begin
633      for j := 0 to Count - 1 do      for j := 0 to bmp_count - 1 do
634      begin      begin
635        case StoneGrid.Strings[i, j] of        case StoneGrid.Strings[i, j] of
636          stWhite:          stWhite:
637            Canvas.DrawBitmap(Image4.Bitmap, RectF(0, 0, Image4.Bitmap.Width,            Canvas.DrawBitmap(Image3.Bitmap, RectF(100, 0, 150, 50),
638              Image4.Bitmap.Height), RectF(i * Size, j * Size, (i + 1) * Size,              RectF(i * Size, j * Size, (i + 1) * Size, (j + 1) * Size), 1);
             (j + 1) * Size), 1);  
639          stBlack:          stBlack:
640            Canvas.DrawBitmap(Image3.Bitmap, RectF(0, 0, Image3.Bitmap.Width,            Canvas.DrawBitmap(Image3.Bitmap, RectF(50, 0, 100, 50),
641              Image3.Bitmap.Height), RectF(i * Size, j * Size, (i + 1) * Size,              RectF(i * Size, j * Size, (i + 1) * Size, (j + 1) * Size), 1);
             (j + 1) * Size), 1);  
642          stEffect:          stEffect:
643            continue;            continue;
644        else        else
645          Canvas.DrawBitmap(Image5.Bitmap, RectF(0, 0, Image5.Bitmap.Width,          Canvas.DrawBitmap(Image3.Bitmap, RectF(0, 0, 50, 50),
646            Image5.Bitmap.Height), RectF(i * Size, j * Size, (i + 1) * Size,            RectF(i * Size, j * Size, (i + 1) * Size, (j + 1) * Size), 1);
           (j + 1) * Size), 1);  
647        end;        end;
648        Canvas.DrawLine(PointF(0, j * Size), PointF(Count * Size, j * Size), 1);        Canvas.DrawLine(PointF(0, j * Size), PointF(bmp_count * Size,
649            j * Size), 1);
650      end;      end;
651      Canvas.DrawLine(PointF(i * Size, 0), PointF(i * Size, Size * Count), 1);      Canvas.DrawLine(PointF(i * Size, 0), PointF(i * Size, Size * bmp_count), 1);
652    end;    end;
653    Canvas.DrawLine(PointF(Count * Size, 0),    Canvas.DrawLine(PointF(bmp_count * Size, 0), PointF(bmp_count * Size,
654      PointF(Count * Size, Count * Size), 1);      bmp_count * Size), 1);
655    Canvas.DrawLine(PointF(0, Count * Size),    Canvas.DrawLine(PointF(0, bmp_count * Size), PointF(bmp_count * Size,
656      PointF(Count * Size, Count * Size), 1);      bmp_count * Size), 1);
657  end;  end;
658    
659  procedure TForm1.PaintBox1Resize(Sender: TObject);  procedure TForm1.PaintBox1Resize(Sender: TObject);
660  begin  begin
661    Size := Min(ClientWidth, ClientHeight) div Count;    Size := Min(ClientWidth, ClientHeight) div bmp_count;
 end;  
   
 procedure TForm1.FormActivate(Sender: TObject);  
 begin  
   Timer1.Enabled := true;  
662  end;  end;
663    
664  procedure TForm1.FormCreate(Sender: TObject);  procedure TForm1.FormCreate(Sender: TObject);
665  begin  begin
666      ClientWidth := 400;
667      ClientHeight := 400;
668    StoneGrid := TStoneGrid.Create;    StoneGrid := TStoneGrid.Create;
669    StoneGrid.ImageCount(Form1.Image1.Bitmap.Width div Form1.Image3.Bitmap.Width,    StoneGrid.ImageCount(6, 5);
     Form1.Image1.Bitmap.Height div Form1.Image3.Bitmap.Height);  
670    Player1 := TPlayer.Create;    Player1 := TPlayer.Create;
671    Player2 := TPlayer.Create;    Player2 := TPlayer.Create;
672    Player1.Stone := stBlack;    Player1.Stone := stBlack;
# Line 613  begin Line 682  begin
682    GameStart;    GameStart;
683  end;  end;
684    
 procedure TForm1.FormDeactivate(Sender: TObject);  
 begin  
   Timer1.Enabled := false;  
 end;  
   
685  procedure TForm1.FormDestroy(Sender: TObject);  procedure TForm1.FormDestroy(Sender: TObject);
686  begin  begin
687    StoneGrid.Free;    StoneGrid.Free;
# Line 645  end; Line 709  end;
709    
710  procedure TForm1.FormResize(Sender: TObject);  procedure TForm1.FormResize(Sender: TObject);
711  begin  begin
712    Size := Min(ClientWidth, ClientHeight) div Count;    Size := Min(ClientWidth, ClientHeight) div bmp_count;
713    PaintTo(Canvas);    PaintTo(Canvas);
714  end;  end;
715    
# Line 654  begin Line 718  begin
718    if Index.Auto = false then    if Index.Auto = false then
719    begin    begin
720      MenuItem10Click(Sender);      MenuItem10Click(Sender);
721        StoneGrid.Active := false;
722      if StoneGrid.CanSetStone(Index.Stone, Floor(Point.X / Size),      if StoneGrid.CanSetStone(Index.Stone, Floor(Point.X / Size),
723        Floor(Point.Y / Size), true, true) = true then        Floor(Point.Y / Size), true, true) = true then
     begin  
724        PaintBox1.Repaint;        PaintBox1.Repaint;
725        ChangePlayer;      StoneGrid.Active := true;
     end;  
726    end;    end;
727  end;  end;
728    

Legend:
Removed from v.25  
changed lines
  Added in v.34

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