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 27 by yamat0jp, Mon Jul 20 09:01:47 2015 UTC revision 28 by yamat0jp, Fri Aug 14 07:21:57 2015 UTC
# Line 39  type Line 39  type
39      FActive: Boolean;      FActive: Boolean;
40      FList: TList;      FList: TList;
41      FEffectStone: TStoneType;      FEffectStone: TStoneType;
     FBool: Boolean;  
     FTerminated: Boolean;  
42      FIndex_X: integer;      FIndex_X: integer;
43      FIndex_Y: integer;      FIndex_Y: integer;
44        FGameOver: Boolean;
45      function GetStrings(X, Y: integer): TStoneType;      function GetStrings(X, Y: integer): TStoneType;
46      procedure SetStrings(X, Y: integer; const Value: TStoneType);      procedure SetStrings(X, Y: integer; const Value: TStoneType);
47      procedure SetTurnNumber(const Value: integer);      procedure SetTurnNumber(const Value: integer);
48        function GetActive: Boolean;
49        procedure SetActive(const Value: Boolean);
50    public    public
51      constructor Create;      constructor Create;
52      destructor Destroy; override;      destructor Destroy; override;
# Line 58  type Line 59  type
59      procedure Restart;      procedure Restart;
60      procedure Pause;      procedure Pause;
61      function ListExecute: Boolean;      function ListExecute: Boolean;
62        procedure GameOver;
63      procedure Paint(Canvas: TCanvas);      procedure Paint(Canvas: TCanvas);
64      procedure ImageCount(X, Y: integer);      procedure ImageCount(X, Y: integer);
65        function AddScore(X, Y: integer; const NG: array of TPoint): integer;
66      property Strings[X, Y: integer]: TStoneType read GetStrings      property Strings[X, Y: integer]: TStoneType read GetStrings
67        write SetStrings; default;        write SetStrings; default;
68      property TurnNumber: integer read FTurnNumber write SetTurnNumber;      property TurnNumber: integer read FTurnNumber write SetTurnNumber;
69      property Active: Boolean read FActive;      property Active: Boolean read GetActive write SetActive;
70    end;    end;
71    
72    TForm1 = class(TForm)    TForm1 = class(TForm)
# Line 128  implementation Line 131  implementation
131  {$R *.Windows.fmx MSWINDOWS}  {$R *.Windows.fmx MSWINDOWS}
132  { TStoneGrid }  { TStoneGrid }
133    
134    function TStoneGrid.AddScore(X, Y: integer; const NG: array of TPoint): integer;
135    var
136      s: TPoint;
137    begin
138      result := 0;
139      for s in NG do
140        if (X = s.X) and (Y = s.Y) then
141        begin
142          result := 10;
143          break;
144        end;
145    end;
146    
147  function TStoneGrid.CalScore(Stone: TStoneType; X, Y: integer): integer;  function TStoneGrid.CalScore(Stone: TStoneType; X, Y: integer): integer;
148  var  var
149    i, j: integer;    i, j: integer;
# Line 135  begin Line 151  begin
151    if CanSetStone(Stone, X, Y, true) = true then    if CanSetStone(Stone, X, Y, true) = true then
152    begin    begin
153      result := 0;      result := 0;
154        inc(result, AddScore(X, Y, [Point(1, 0), Point(6, 0), Point(0, 1),
155          Point(1, 1), Point(6, 1), Point(7, 1), Point(0, 6), Point(1, 6),
156          Point(6, 6), Point(7, 6), Point(1, 7), Point(6, 7)]));
157      case Stone of      case Stone of
158        stBlack:        stBlack:
159          Stone := stWhite;          Stone := stWhite;
# Line 144  begin Line 163  begin
163      for i := 0 to Count - 1 do      for i := 0 to Count - 1 do
164        for j := 0 to Count - 1 do        for j := 0 to Count - 1 do
165          if CanSetStone(Stone, i, j, false) = true then          if CanSetStone(Stone, i, j, false) = true then
166            begin
167            inc(result);            inc(result);
168              inc(result, AddScore(i, j, [Point(0, 0), Point(7, 0), Point(0, 7),
169                Point(7, 7)]));
170            end;
171    end    end
172    else    else
173      result := -1;      result := -1;
# Line 219  var Line 242  var
242    
243  begin  begin
244    result := false;    result := false;
   if Visible = true then  
   begin  
     FBool := FActive;  
     FActive := false;  
   end;  
245    p := true;    p := true;
246    if GetStrings(X, Y) = stNone then    if GetStrings(X, Y) = stNone then
247    begin    begin
# Line 273  begin Line 291  begin
291    inherited;    inherited;
292  end;  end;
293    
294    procedure TStoneGrid.GameOver;
295    begin
296      FGameOver := true;
297      FActive := false;
298    end;
299    
300    function TStoneGrid.GetActive: Boolean;
301    begin
302      if (FActive = true) and (FList.Count = 0) then
303        result := true
304      else
305        result := false;
306    end;
307    
308  function TStoneGrid.GetStrings(X, Y: integer): TStoneType;  function TStoneGrid.GetStrings(X, Y: integer): TStoneType;
309  begin  begin
310    if (X >= 0) and (X < Count) and (Y >= 0) and (Y < Count) then    if (X >= 0) and (X < Count) and (Y >= 0) and (Y < Count) then
# Line 318  begin Line 350  begin
350          FList.Delete(i);          FList.Delete(i);
351      if FList.Count = 0 then      if FList.Count = 0 then
352      begin      begin
       if FTerminated = true then  
         FActive := false  
       else  
         FActive := FBool;  
353        inc(FTurnIndex);        inc(FTurnIndex);
354        inc(FTurnNumber);        inc(FTurnNumber);
355        FBuffer[FTurnIndex] := FStrings;        FBuffer[FTurnIndex] := FStrings;
# Line 374  end; Line 402  end;
402  procedure TStoneGrid.Pause;  procedure TStoneGrid.Pause;
403  begin  begin
404    FActive := false;    FActive := false;
   FTerminated := true;  
405  end;  end;
406    
407  procedure TStoneGrid.Restart;  procedure TStoneGrid.Restart;
408  begin  begin
409    FActive := true;    FActive := true;
410      FGameOver := false;
411    FTurnIndex := FTurnNumber;    FTurnIndex := FTurnNumber;
412    FTerminated := false;  end;
413    
414    procedure TStoneGrid.SetActive(const Value: Boolean);
415    begin
416      if FGameOver = false then
417        FActive := Value;
418  end;  end;
419    
420  procedure TStoneGrid.SetStrings(X, Y: integer; const Value: TStoneType);  procedure TStoneGrid.SetStrings(X, Y: integer; const Value: TStoneType);
# Line 403  end; Line 436  end;
436    
437  procedure TStoneGrid.Start;  procedure TStoneGrid.Start;
438  begin  begin
   Clear;  
   FTerminated := false;  
439    FActive := true;    FActive := true;
440      Clear;
441      FGameOver := false;
442  end;  end;
443    
444  { TForm1 }  { TForm1 }
# Line 466  begin Line 499  begin
499          s := 'Player2 Win:' + #13#10          s := 'Player2 Win:' + #13#10
500        else        else
501          s := 'Draw:' + #13#10;          s := 'Draw:' + #13#10;
502          StoneGrid.GameOver;
503        Showmessage(s + '(Player1) ' + IntToStr(m) + #13#10 + '(Player2) ' +        Showmessage(s + '(Player1) ' + IntToStr(m) + #13#10 + '(Player2) ' +
504          IntToStr(n));          IntToStr(n));
505      end      end
# Line 480  procedure TForm1.CompStone; Line 514  procedure TForm1.CompStone;
514  var  var
515    s: TPoint;    s: TPoint;
516  begin  begin
517    if StoneGrid.NextStone(Index.Stone, s) = true then    StoneGrid.Active := false;
518    begin    StoneGrid.NextStone(Index.Stone, s);
519      StoneGrid.CanSetStone(Index.Stone, s.X, s.Y, true, true);    StoneGrid.CanSetStone(Index.Stone, s.X, s.Y, true, true);
520      PaintBox1.Repaint;    PaintBox1.Repaint;
   end;  
521    ChangePlayer;    ChangePlayer;
522      StoneGrid.Active := true;
523  end;  end;
524    
525  procedure TForm1.GameStart;  procedure TForm1.GameStart;
# Line 523  end; Line 557  end;
557    
558  procedure TForm1.MenuItem2Click(Sender: TObject);  procedure TForm1.MenuItem2Click(Sender: TObject);
559  begin  begin
560      Timer1.Enabled := false;
561      Timer2.Enabled := false;
562    GameStart;    GameStart;
563      Timer1.Enabled := true;
564      Timer2.Enabled := true;
565  end;  end;
566    
567  procedure TForm1.MenuItem4Click(Sender: TObject);  procedure TForm1.MenuItem4Click(Sender: TObject);
# Line 639  begin Line 677  begin
677    if Index.Auto = false then    if Index.Auto = false then
678    begin    begin
679      MenuItem10Click(Sender);      MenuItem10Click(Sender);
680        StoneGrid.Active := false;
681      if StoneGrid.CanSetStone(Index.Stone, Floor(Point.X / Size),      if StoneGrid.CanSetStone(Index.Stone, Floor(Point.X / Size),
682        Floor(Point.Y / Size), true, true) = true then        Floor(Point.Y / Size), true, true) = true then
683      begin      begin
684        PaintBox1.Repaint;        PaintBox1.Repaint;
685        ChangePlayer;        ChangePlayer;
686      end;      end;
687        StoneGrid.Active := true;
688    end;    end;
689  end;  end;
690    

Legend:
Removed from v.27  
changed lines
  Added in v.28

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