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 23 by yamat0jp, Sat Jul 18 23:47:44 2015 UTC revision 37 by yamat0jp, Sun Aug 30 08:32:57 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 17  type Line 17  type
17    TEffectData = record    TEffectData = record
18      X, Y: integer;      X, Y: integer;
19      Left, Top: integer;      Left, Top: integer;
     Stone: TStoneType;  
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 31  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      List: 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 87  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 127  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 > 1 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              if (loop mod 2) > 0 then
188                inc(Score)
189              else
190                dec(Score);
191              case Stone of
192                stBlack:
193                  Stone := stWhite;
194                stWhite:
195                  Stone := stBlack;
196              end;
197              Hard;
198              if loop > 1 then
199              begin
200                Easy;
201                FStrings := FBuffer[FTurnIndex + loop];
202              end
203              else
204                FBuffer[FTurnIndex + loop] := FStrings;
205            end;
206          end;
207        dec(loop);
208      end;
209    
210  begin  begin
211    if CanSetStone(Stone, X, Y, true) = true then    if CanSetStone(Stone, X, Y, true) = true then
212    begin    begin
213        Score := 0;
214        result := true;
215        if FTurnIndex < 50 then
216          inc(Score, AddScore(X, Y, waste));
217        dec(Score, AddScore(X, Y, worth));
218      case Stone of      case Stone of
219        stBlack:        stBlack:
220          Stone := stWhite;          Stone := stWhite;
221        stWhite:        stWhite:
222          Stone := stBlack;          Stone := stBlack;
       stEffect:  
         Stone := FEffectStone;  
223      end;      end;
224      result := 0;      if (Form1.MenuItem14.IsChecked = true) and (FTurnIndex + 2 <= 60) then
225      for i := 0 to Count - 1 do      begin
226        for j := 0 to Count - 1 do        loop := 0;
227          if CanSetStone(Stone, i, j, false) = true then        Hard;
228            inc(result);      end
229      FStrings := FBuffer[FTurnIndex];      else
230          Easy;
231    end    end
232    else    else
233    begin      result := false;
234      FStrings := FBuffer[FTurnIndex];    FStrings := FBuffer[FTurnIndex];
     result := -1;  
   end;  
235  end;  end;
236    
237  function TStoneGrid.CanSetStone(Stone: TStoneType; X, Y: integer;  function TStoneGrid.CanSetStone(Stone: TStoneType; X, Y: integer;
# Line 162  function TStoneGrid.CanSetStone(Stone: T Line 239  function TStoneGrid.CanSetStone(Stone: T
239  var  var
240    i: integer;    i: integer;
241    p: Boolean;    p: Boolean;
242    q: ^TEffectData;    q: TEffectData;
243    procedure Method(m, n: integer);    procedure Method(m, n: integer);
244    var    var
245      s: TStoneType;      s: TStoneType;
246      j, k: integer;      j: integer;
247        k: integer;
248    begin    begin
249      if p = false then      if p = false then
250        Exit;        Exit;
# Line 186  var Line 264  var
264            result := true;            result := true;
265            if Reverse = true then            if Reverse = true then
266            begin            begin
267                Form1.PaintBox1.Repaint;
268              for j := 1 to i - 1 do              for j := 1 to i - 1 do
269              begin              begin
               Form1.PaintBox1.Repaint;  
270                if Visible = true then                if Visible = true then
271                begin                begin
272                  FEffectStone := Stone;                  FEffectStone := Stone;
273                  New(q);                  q.Left := X + m * j;
274                  q^.Left := X + m * j;                  q.Top := Y + n * j;
275                  q^.Top := Y + n * j;                  q.X := 0;
276                  q^.Stone := Stone;                  q.Y := 0;
277                  q^.X := 0;                  FList.Add(q);
278                  q^.Y := 0;                  SetStrings(q.Left, q.Top, stEffect);
279                  List.Add(q);                  for k := 1 to 10 do
                 SetStrings(q^.Left, q^.Top, stEffect);  
                 for k := 1 to 100 do  
280                  begin                  begin
281                    Sleep(1);                    Sleep(15);
282                    Application.ProcessMessages;                    Application.ProcessMessages;
283                  end;                  end;
284                end                end
# Line 226  var Line 302  var
302    
303  begin  begin
304    result := false;    result := false;
   if Visible = true then  
   begin  
     FBool := FActive;  
     FActive := false;  
   end;  
305    p := true;    p := true;
306    if GetStrings(X, Y) = stNone then    if GetStrings(X, Y) = stNone then
307    begin    begin
# Line 249  procedure TStoneGrid.Clear; Line 320  procedure TStoneGrid.Clear;
320  var  var
321    i, j: integer;    i, j: integer;
322  begin  begin
323    for i := 0 to Count - 1 do    FList.Clear;
324      for j := 0 to Count - 1 do    for i := 0 to bmp_count - 1 do
325        for j := 0 to bmp_count - 1 do
326        Strings[i, j] := stNone;        Strings[i, j] := stNone;
327    Strings[3, 3] := stBlack;    Strings[3, 3] := stBlack;
328    Strings[4, 4] := stBlack;    Strings[4, 4] := stBlack;
# Line 264  end; Line 336  end;
336  constructor TStoneGrid.Create;  constructor TStoneGrid.Create;
337  begin  begin
338    inherited;    inherited;
339    List := TList.Create;    FList := TList<TEffectData>.Create;
340  end;  end;
341    
342  destructor TStoneGrid.Destroy;  destructor TStoneGrid.Destroy;
 var  
   i: integer;  
343  begin  begin
344    for i := 0 to List.Count - 1 do    FList.Free;
     Dispose(List[i]);  
   List.Free;  
345    inherited;    inherited;
346  end;  end;
347    
348    procedure TStoneGrid.GameOver;
349    begin
350      FGameOver := true;
351      FActive := false;
352    end;
353    
354    function TStoneGrid.GetActive: Boolean;
355    begin
356      if (FActive = true) and (FList.Count = 0) then
357        result := true
358      else
359        result := false;
360    end;
361    
362  function TStoneGrid.GetStrings(X, Y: integer): TStoneType;  function TStoneGrid.GetStrings(X, Y: integer): TStoneType;
363  begin  begin
364    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
365      result := FStrings[X, Y]      result := FStrings[X, Y]
366    else    else
367      result := stError;      result := stError;
# Line 293  end; Line 375  end;
375    
376  function TStoneGrid.ListExecute: Boolean;  function TStoneGrid.ListExecute: Boolean;
377  var  var
   p: ^TEffectData;  
378    i: integer;    i: integer;
379      s: TEffectData;
380  begin  begin
381    if List.Count = 0 then    if FList.Count = 0 then
382      result := false      result := false
383    else    else
384    begin    begin
385      for i := 0 to List.Count - 1 do      i := 0;
386        while i < FList.Count do
387      begin      begin
388        p := List.List[i];        s := FList[i];
389        if p^.X < FIndex_X - 1 then        if s.X < FIndex_X - 1 then
390          p^.X := p^.X + 1          s.X := s.X + 1
391        else if p^.Y < FIndex_Y - 1 then        else if s.Y < FIndex_Y - 1 then
392        begin        begin
393          p^.X := 0;          s.X := 0;
394          p^.Y := p^.Y + 1;          s.Y := s.Y + 1;
395        end        end
396        else        else
397        begin        begin
398          SetStrings(p^.Left, p^.Top, p^.Stone);          SetStrings(s.Left, s.Top, FEffectStone);
399          Dispose(p);          FList.Delete(i);
400          List[i] := nil;          inc(i);
401            continue;
402        end;        end;
403          FList[i] := s;
404          inc(i);
405      end;      end;
406      for i := List.Count - 1 downto 0 do      if FList.Count = 0 then
       if List[i] = nil then  
         List.Delete(i);  
     if List.Count = 0 then  
407      begin      begin
       if FTerminated = true then  
         FActive := false  
       else  
         FActive := FBool;  
408        inc(FTurnIndex);        inc(FTurnIndex);
409        inc(FTurnNumber);        inc(FTurnNumber);
410        FBuffer[FTurnIndex] := FStrings;        FBuffer[FTurnIndex] := FStrings;
411          Form1.PaintBox1.Repaint;
412          Form1.ChangePlayer;
413          if FGameOver = false then
414            FActive := true
415      end;      end;
416      result := true;      result := true;
417    end;    end;
418  end;  end;
419    
420  function TStoneGrid.NextStone(Stone: TStoneType): TPoint;  function TStoneGrid.NextStone(Stone: TStoneType; var Pos: TPoint): Boolean;
421  var  var
422    i, j, m, n: integer;    i, j, m, n: integer;
423  begin  begin
424    n := -1;    result := false;
425    for i := 0 to Count - 1 do    n := 0;
426      for j := 0 to Count - 1 do    for i := 0 to bmp_count - 1 do
427      begin      for j := 0 to bmp_count - 1 do
428        m := CalScore(Stone, i, j);        if (CalScore(Stone, i, j, m) = true) and ((result = false) or (m < n))
429        if (n = -1) or ((m > -1) and (n > m)) then        then
430        begin        begin
431            if result = false then
432              result := true;
433          n := m;          n := m;
434          result := Point(i, j);          Pos := Point(i, j);
435        end;        end;
     end;  
   if n = -1 then  
     result := Point(-1, -1);  
436  end;  end;
437    
438  procedure TStoneGrid.Paint(Canvas: TCanvas);  procedure TStoneGrid.Paint(Canvas: TCanvas);
439  var  var
440    i: integer;    k: integer;
   k, m, n: integer;  
441    s: TBitmap;    s: TBitmap;
442    p: ^TEffectData;    p: TEffectData;
443  begin  begin
   m := Form1.Image3.Bitmap.Width;  
   n := Form1.Image3.Bitmap.Height;  
444    k := Form1.Size;    k := Form1.Size;
445    for i := 0 to List.Count - 1 do    if FEffectStone = stBlack then
446        s := Form1.Image1.Bitmap
447      else
448        s := Form1.Image2.Bitmap;
449      for p in FList do
450    begin    begin
451      p := List[i];      Canvas.DrawBitmap(s, RectF(p.X * 50, p.Y * 50, (p.X + 1) * 50,
452      if p^.Stone = stBlack then        (p.Y + 1) * 50), RectF(p.Left * k, p.Top * k, (p.Left + 1) * k,
453        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);  
454    end;    end;
455  end;  end;
456    
457  procedure TStoneGrid.Pause;  procedure TStoneGrid.Pause;
458  begin  begin
459    if FActive = true then    FActive := false;
     FActive := false;  
   FTerminated := true;  
460  end;  end;
461    
462  procedure TStoneGrid.Restart;  procedure TStoneGrid.Restart;
463  begin  begin
464    if FTerminated = true then    FActive := true;
465    begin    FGameOver := false;
466      FActive := true;    FTurnIndex := FTurnNumber;
467      FTurnIndex := FTurnNumber;  end;
468      FTerminated := false;  
469    end;  procedure TStoneGrid.SetActive(const Value: Boolean);
470    begin
471      if (FGameOver = false) or (Value = false) then
472        FActive := Value;
473  end;  end;
474    
475  procedure TStoneGrid.SetStrings(X, Y: integer; const Value: TStoneType);  procedure TStoneGrid.SetStrings(X, Y: integer; const Value: TStoneType);
476  begin  begin
477    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
478      FStrings[X, Y] := Value;      FStrings[X, Y] := Value;
479  end;  end;
480    
# Line 412  end; Line 491  end;
491    
492  procedure TStoneGrid.Start;  procedure TStoneGrid.Start;
493  begin  begin
   FActive := false;  
494    Clear;    Clear;
   FTerminated := false;  
495    FActive := true;    FActive := true;
496      FGameOver := false;
497  end;  end;
498    
499  { TForm1 }  { TForm1 }
# Line 440  var Line 518  var
518    function Execute: Boolean;    function Execute: Boolean;
519    var    var
520      i, j: integer;      i, j: integer;
     m: integer;  
     n: integer;  
521    begin    begin
522      for i := 0 to Count - 1 do      for i := 0 to bmp_count - 1 do
523        for j := 0 to Count - 1 do        for j := 0 to bmp_count - 1 do
524          if StoneGrid.CanSetStone(Index.Stone, i, j, false) = true then          if StoneGrid.CanSetStone(Index.Stone, i, j, false) = true then
525          begin          begin
526            result := true;            result := true;
# Line 454  var Line 530  var
530    end;    end;
531    
532  begin  begin
   Timer1.Enabled := false;  
533    Main;    Main;
534    if Execute = false then    if Execute = false then
535    begin    begin
536      Main;      Main;
537      if Execute = false then      if Execute = false then
538      begin      begin
       StoneGrid.Pause;  
539        m := 0;        m := 0;
540        n := 0;        n := 0;
541        for i := 0 to Count - 1 do        for i := 0 to bmp_count - 1 do
542          for j := 0 to Count - 1 do          for j := 0 to bmp_count - 1 do
543            case StoneGrid[i, j] of            case StoneGrid[i, j] of
544              stBlack:              stBlack:
545                inc(m);                inc(m);
# Line 479  begin Line 553  begin
553          s := 'Player2 Win:' + #13#10          s := 'Player2 Win:' + #13#10
554        else        else
555          s := 'Draw:' + #13#10;          s := 'Draw:' + #13#10;
556        Showmessage(s + '(Player1) ' + IntToStr(m) + #13#10 + '(Player2) ' +        StoneGrid.GameOver;
557          IntToStr(n));        Showmessage(s + '(Player1) ' + m.ToString + #13#10 + '(Player2) ' +
558            n.ToString);
559      end      end
560      else      else
561        Caption := s;        Caption := s;
562    end    end
563    else    else
564      Caption := s;      Caption := s;
   Timer1.Enabled := true;  
565  end;  end;
566    
567  procedure TForm1.CompStone;  procedure TForm1.CompStone;
568  var  var
569    s: TPoint;    s: TPoint;
570  begin  begin
571    s := StoneGrid.NextStone(Index.Stone);    StoneGrid.Active := false;
572    StoneGrid.CanSetStone(Index.Stone, s.X, s.Y, true, true);    if StoneGrid.NextStone(Index.Stone, s) = true then
573    PaintBox1.Repaint;    begin
574    ChangePlayer;      StoneGrid.CanSetStone(Index.Stone, s.X, s.Y, true, true);
575        PaintBox1.Repaint;
576      end
577      else
578        ChangePlayer;
579  end;  end;
580    
581  procedure TForm1.GameStart;  procedure TForm1.GameStart;
# Line 535  end; Line 613  end;
613    
614  procedure TForm1.MenuItem2Click(Sender: TObject);  procedure TForm1.MenuItem2Click(Sender: TObject);
615  begin  begin
616      Timer1.Enabled := false;
617      Timer2.Enabled := false;
618    GameStart;    GameStart;
619      Timer1.Enabled := true;
620      Timer2.Enabled := true;
621  end;  end;
622    
623  procedure TForm1.MenuItem4Click(Sender: TObject);  procedure TForm1.MenuItem4Click(Sender: TObject);
# Line 560  var Line 642  var
642  begin  begin
643    if StoneGrid.Active = false then    if StoneGrid.Active = false then
644      StoneGrid.Paint(Canvas);      StoneGrid.Paint(Canvas);
645    for i := 0 to Count - 1 do    for i := 0 to bmp_count - 1 do
646    begin    begin
647      for j := 0 to Count - 1 do      for j := 0 to bmp_count - 1 do
648      begin      begin
649        case StoneGrid.Strings[i, j] of        case StoneGrid.Strings[i, j] of
650          stWhite:          stWhite:
651            Canvas.DrawBitmap(Image4.Bitmap, RectF(0, 0, Image4.Bitmap.Width,            Canvas.DrawBitmap(Image3.Bitmap, RectF(100, 0, 150, 50),
652              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);  
653          stBlack:          stBlack:
654            Canvas.DrawBitmap(Image3.Bitmap, RectF(0, 0, Image3.Bitmap.Width,            Canvas.DrawBitmap(Image3.Bitmap, RectF(50, 0, 100, 50),
655              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);  
656          stEffect:          stEffect:
657            continue;            continue;
658        else        else
659          Canvas.DrawBitmap(Image5.Bitmap, RectF(0, 0, Image5.Bitmap.Width,          Canvas.DrawBitmap(Image3.Bitmap, RectF(0, 0, 50, 50),
660            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);  
661        end;        end;
662        Canvas.DrawLine(PointF(0, j * Size), PointF(Count * Size, j * Size), 1);        Canvas.DrawLine(PointF(0, j * Size), PointF(bmp_count * Size,
663            j * Size), 1);
664      end;      end;
665      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);
666    end;    end;
667    Canvas.DrawLine(PointF(Count * Size, 0),    Canvas.DrawLine(PointF(bmp_count * Size, 0), PointF(bmp_count * Size,
668      PointF(Count * Size, Count * Size), 1);      bmp_count * Size), 1);
669    Canvas.DrawLine(PointF(0, Count * Size),    Canvas.DrawLine(PointF(0, bmp_count * Size), PointF(bmp_count * Size,
670      PointF(Count * Size, Count * Size), 1);      bmp_count * Size), 1);
671  end;  end;
672    
673  procedure TForm1.PaintBox1Resize(Sender: TObject);  procedure TForm1.PaintBox1Resize(Sender: TObject);
674  begin  begin
675    Size := Min(ClientWidth, ClientHeight) div Count;    Size := Min(ClientWidth, ClientHeight) div bmp_count;
676  end;  end;
677    
678  procedure TForm1.FormCreate(Sender: TObject);  procedure TForm1.FormCreate(Sender: TObject);
679  begin  begin
680      ClientWidth := 400;
681      ClientHeight := 400;
682    StoneGrid := TStoneGrid.Create;    StoneGrid := TStoneGrid.Create;
683    StoneGrid.ImageCount(Form1.Image1.Bitmap.Width div Form1.Image3.Bitmap.Width,    StoneGrid.ImageCount(6, 5);
     Form1.Image1.Bitmap.Height div Form1.Image3.Bitmap.Height);  
684    Player1 := TPlayer.Create;    Player1 := TPlayer.Create;
685    Player2 := TPlayer.Create;    Player2 := TPlayer.Create;
686    Player1.Stone := stBlack;    Player1.Stone := stBlack;
# Line 642  end; Line 723  end;
723    
724  procedure TForm1.FormResize(Sender: TObject);  procedure TForm1.FormResize(Sender: TObject);
725  begin  begin
726    Size := Min(ClientWidth, ClientHeight) div Count;    Size := Min(ClientWidth, ClientHeight) div bmp_count;
727    PaintTo(Canvas);    PaintTo(Canvas);
728  end;  end;
729    
# Line 651  begin Line 732  begin
732    if Index.Auto = false then    if Index.Auto = false then
733    begin    begin
734      MenuItem10Click(Sender);      MenuItem10Click(Sender);
735        StoneGrid.Active := false;
736      if StoneGrid.CanSetStone(Index.Stone, Floor(Point.X / Size),      if StoneGrid.CanSetStone(Index.Stone, Floor(Point.X / Size),
737        Floor(Point.Y / Size), true, true) = true then        Floor(Point.Y / Size), true, true) = true then
     begin  
738        PaintBox1.Repaint;        PaintBox1.Repaint;
739        ChangePlayer;      StoneGrid.Active := true;
     end;  
740    end;    end;
741  end;  end;
742    

Legend:
Removed from v.23  
changed lines
  Added in v.37

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