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

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

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