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 22 by yamat0jp, Sat Jul 18 22:44:20 2015 UTC revision 25 by yamat0jp, Mon Jul 20 00:50:13 2015 UTC
# 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 .. Count - 1] of array [0 .. Count - 1] of TStoneType;
# Line 38  type Line 37  type
37      FTurnNumber: integer;      FTurnNumber: integer;
38      FTurnIndex: integer;      FTurnIndex: integer;
39      FActive: Boolean;      FActive: Boolean;
40      List: TList;      FList: TList;
41      FEffectStone: TStoneType;      FEffectStone: TStoneType;
42      FBool: Boolean;      FBool: Boolean;
43      FTerminated: Boolean;      FTerminated: Boolean;
# Line 105  type Line 104  type
104      procedure MenuItem10Click(Sender: TObject);      procedure MenuItem10Click(Sender: TObject);
105      procedure MenuItem11Click(Sender: TObject);      procedure MenuItem11Click(Sender: TObject);
106      procedure Timer2Timer(Sender: TObject);      procedure Timer2Timer(Sender: TObject);
107        procedure FormDeactivate(Sender: TObject);
108        procedure FormActivate(Sender: TObject);
109    private    private
110      { Private 宣言 }      { Private 宣言 }
111      StoneGrid: TStoneGrid;      StoneGrid: TStoneGrid;
# Line 133  function TStoneGrid.CalScore(Stone: TSto Line 134  function TStoneGrid.CalScore(Stone: TSto
134  var  var
135    i, j: integer;    i, j: integer;
136  begin  begin
137      result:=0;
138    if CanSetStone(Stone, X, Y, true) = true then    if CanSetStone(Stone, X, Y, true) = true then
139    begin    begin
140        if Stone = stEffect then
141          Stone:=FEffectStone;
142      case Stone of      case Stone of
143      stBlack:        stBlack:
144        Stone := stWhite;          Stone := stWhite;
145      stWhite:        stWhite:
146        Stone := stBlack;          Stone := stBlack;
147      stEffect:        else
148        Stone := FEffectStone;          Exit;
149      end;      end;
     result := 0;  
150      for i := 0 to Count - 1 do      for i := 0 to Count - 1 do
151        for j := 0 to Count - 1 do        for j := 0 to Count - 1 do
152          if CanSetStone(Stone, i, j, false) = true then          if CanSetStone(Stone, i, j, false) = true then
153            inc(result);            inc(result);
     FStrings := FBuffer[FTurnIndex];  
   end  
   else  
   begin  
     FStrings := FBuffer[FTurnIndex];  
     result := -1;  
154    end;    end;
155      FStrings := FBuffer[FTurnIndex];
156  end;  end;
157    
158  function TStoneGrid.CanSetStone(Stone: TStoneType; X, Y: integer;  function TStoneGrid.CanSetStone(Stone: TStoneType; X, Y: integer;
# Line 175  var Line 173  var
173      begin      begin
174        s := GetStrings(X + m * i, Y + n * i);        s := GetStrings(X + m * i, Y + n * i);
175        if s = stEffect then        if s = stEffect then
176          s:=FEffectStone;          s := FEffectStone;
177        if (s = stNone) or (s = stError) then        if (s = stNone) or (s = stError) then
178          break          break
179        else if s = Stone then        else if s = Stone then
# Line 191  var Line 189  var
189                Form1.PaintBox1.Repaint;                Form1.PaintBox1.Repaint;
190                if Visible = true then                if Visible = true then
191                begin                begin
192                  FEffectStone:=Stone;                  FEffectStone := Stone;
193                  New(q);                  New(q);
194                  q^.Left := X + m * j;                  q^.Left := X + m * j;
195                  q^.Top := Y + n * j;                  q^.Top := Y + n * j;
                 q^.Stone := Stone;  
196                  q^.X := 0;                  q^.X := 0;
197                  q^.Y := 0;                  q^.Y := 0;
198                  List.Add(q);                  FList.Add(q);
199                  SetStrings(q^.Left, q^.Top, stEffect);                  SetStrings(q^.Left, q^.Top, stEffect);
200                  for k := 1 to 100 do                  for k := 1 to 100 do
201                  begin                  begin
# Line 249  procedure TStoneGrid.Clear; Line 246  procedure TStoneGrid.Clear;
246  var  var
247    i, j: integer;    i, j: integer;
248  begin  begin
249      for i := 0 to FList.Count - 1 do
250        Dispose(FList[i]);
251      FList.Clear;
252    for i := 0 to Count - 1 do    for i := 0 to Count - 1 do
253      for j := 0 to Count - 1 do      for j := 0 to Count - 1 do
254        Strings[i, j] := stNone;        Strings[i, j] := stNone;
# Line 264  end; Line 264  end;
264  constructor TStoneGrid.Create;  constructor TStoneGrid.Create;
265  begin  begin
266    inherited;    inherited;
267    List := TList.Create;    FList := TList.Create;
268  end;  end;
269    
270  destructor TStoneGrid.Destroy;  destructor TStoneGrid.Destroy;
271  var  var
272    i: integer;    i: integer;
273  begin  begin
274    for i := 0 to List.Count - 1 do    for i := 0 to FList.Count - 1 do
275      Dispose(List[i]);      Dispose(FList[i]);
276    List.Free;    FList.Free;
277    inherited;    inherited;
278  end;  end;
279    
# Line 296  var Line 296  var
296    p: ^TEffectData;    p: ^TEffectData;
297    i: integer;    i: integer;
298  begin  begin
299    if List.Count = 0 then    if FList.Count = 0 then
300      result := false      result := false
301    else    else
302    begin    begin
303      for i := 0 to List.Count - 1 do      for i := 0 to FList.Count - 1 do
304      begin      begin
305        p := List.List[i];        p := FList[i];
306        if p^.X < FIndex_X - 1 then        if p^.X < FIndex_X - 1 then
307          p^.X := p^.X + 1          p^.X := p^.X + 1
308        else if p^.Y < FIndex_Y - 1 then        else if p^.Y < FIndex_Y - 1 then
# Line 312  begin Line 312  begin
312        end        end
313        else        else
314        begin        begin
315          SetStrings(p^.Left, p^.Top, p^.Stone);          SetStrings(p^.Left, p^.Top, FEffectStone);
316          Dispose(p);          Dispose(p);
317          List[i] := nil;          FList[i] := nil;
318        end;        end;
319      end;      end;
320      for i := List.Count - 1 downto 0 do      for i := FList.Count - 1 downto 0 do
321        if List[i] = nil then        if FList[i] = nil then
322          List.Delete(i);          FList.Delete(i);
323      if List.Count = 0 then      if FList.Count = 0 then
324      begin      begin
325        if FTerminated = true then        if FTerminated = true then
326          FActive:=false          FActive := false
327        else        else
328          FActive := FBool;          FActive := FBool;
329        inc(FTurnIndex);        inc(FTurnIndex);
# Line 338  function TStoneGrid.NextStone(Stone: TSt Line 338  function TStoneGrid.NextStone(Stone: TSt
338  var  var
339    i, j, m, n: integer;    i, j, m, n: integer;
340  begin  begin
341    n := -1;    n := 0;
342    for i := 0 to Count - 1 do    for i := 0 to Count - 1 do
343      for j := 0 to Count - 1 do      for j := 0 to Count - 1 do
344      begin      begin
345        m := CalScore(Stone, i, j);        m := CalScore(Stone, i, j);
346        if (n = -1) or ((m > -1) and (n > m)) then        if ((n = 0)and(m > 0)) or ((0 < m) and (m < n)) then
347        begin        begin
348          n := m;          n := m;
349          result := Point(i, j);          result := Point(i, j);
350        end;        end;
351      end;      end;
352    if n = -1 then    if n = 0 then
353      result := Point(-1, -1);      result := Point(-1, -1);
354  end;  end;
355    
# Line 363  begin Line 363  begin
363    m := Form1.Image3.Bitmap.Width;    m := Form1.Image3.Bitmap.Width;
364    n := Form1.Image3.Bitmap.Height;    n := Form1.Image3.Bitmap.Height;
365    k := Form1.Size;    k := Form1.Size;
366    for i := 0 to List.Count - 1 do    for i := 0 to FList.Count - 1 do
367    begin    begin
368      p := List[i];      p := FList[i];
369      if p^.Stone = stBlack then      if FEffectStone = stBlack then
370        s := Form1.Image1.Bitmap        s := Form1.Image1.Bitmap
371      else      else
372        s := Form1.Image2.Bitmap;        s := Form1.Image2.Bitmap;
# Line 378  end; Line 378  end;
378    
379  procedure TStoneGrid.Pause;  procedure TStoneGrid.Pause;
380  begin  begin
381    FTerminated:=true;    FActive := false;
382      FTerminated := true;
383  end;  end;
384    
385  procedure TStoneGrid.Restart;  procedure TStoneGrid.Restart;
386  begin  begin
387    if FTerminated = true then    FActive := true;
388    begin    FTurnIndex := FTurnNumber;
389      FActive := true;    FTerminated := false;
     FTurnIndex := FTurnNumber;  
     FTerminated:=false;  
   end;  
390  end;  end;
391    
392  procedure TStoneGrid.SetStrings(X, Y: integer; const Value: TStoneType);  procedure TStoneGrid.SetStrings(X, Y: integer; const Value: TStoneType);
# Line 410  end; Line 408  end;
408    
409  procedure TStoneGrid.Start;  procedure TStoneGrid.Start;
410  begin  begin
   FActive:=false;  
411    Clear;    Clear;
412    FTerminated:=false;    FTerminated := false;
413    FActive := true;    FActive := true;
414  end;  end;
415    
# Line 438  var Line 435  var
435    function Execute: Boolean;    function Execute: Boolean;
436    var    var
437      i, j: integer;      i, j: integer;
     m: integer;  
     n: integer;  
438    begin    begin
439      for i := 0 to Count - 1 do      for i := 0 to Count - 1 do
440        for j := 0 to Count - 1 do        for j := 0 to Count - 1 do
# Line 498  end; Line 493  end;
493    
494  procedure TForm1.GameStart;  procedure TForm1.GameStart;
495  begin  begin
496      Timer1.Enabled:=false;
497    Index := Player1;    Index := Player1;
498    StoneGrid.Start;    StoneGrid.Start;
499    PaintBox1.Repaint;    PaintBox1.Repaint;
500    Caption := '黒から始めます';    Caption := '黒から始めます';
501      Timer1.Enabled:=true;
502  end;  end;
503    
504  procedure TForm1.MenuItem10Click(Sender: TObject);  procedure TForm1.MenuItem10Click(Sender: TObject);
# Line 591  begin Line 588  begin
588    Size := Min(ClientWidth, ClientHeight) div Count;    Size := Min(ClientWidth, ClientHeight) div Count;
589  end;  end;
590    
591    procedure TForm1.FormActivate(Sender: TObject);
592    begin
593      Timer1.Enabled := true;
594    end;
595    
596  procedure TForm1.FormCreate(Sender: TObject);  procedure TForm1.FormCreate(Sender: TObject);
597  begin  begin
598    StoneGrid := TStoneGrid.Create;    StoneGrid := TStoneGrid.Create;
# Line 611  begin Line 613  begin
613    GameStart;    GameStart;
614  end;  end;
615    
616    procedure TForm1.FormDeactivate(Sender: TObject);
617    begin
618      Timer1.Enabled := false;
619    end;
620    
621  procedure TForm1.FormDestroy(Sender: TObject);  procedure TForm1.FormDestroy(Sender: TObject);
622  begin  begin
623    StoneGrid.Free;    StoneGrid.Free;
# Line 632  end; Line 639  end;
639    
640  procedure TForm1.Timer2Timer(Sender: TObject);  procedure TForm1.Timer2Timer(Sender: TObject);
641  begin  begin
642    if (StoneGrid.Active = false)and(StoneGrid.ListExecute = true) then    if (StoneGrid.Active = false) and (StoneGrid.ListExecute = true) then
643      PaintBox1.Repaint;      PaintBox1.Repaint;
644  end;  end;
645    

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

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