Einzelnen Beitrag anzeigen

Benutzerbild von R2D2
R2D2

Registriert seit: 20. Jan 2006
Ort: München
253 Beiträge
 
Delphi 2005 Personal
 
#10

Re: Game of Life-Quellcode funzt nicht

  Alt 23. Feb 2006, 08:53
Mache es jetzt mit folgendem Code. Er funzt.
Delphi-Quellcode:
procedure TGOL.Live;
var x,y,i,n, n2, w: Integer; s1, s2, s3, sn, strings: String;
begin
  {sl2 rücksetzen
  for n := 0 to (sl2.Count)-1 do
  begin
    sl2.Strings[n] := '000000000000';
  end;
  }

  //Reihen
  strings := '';
  for y := 0 to trunc(self.Height / zoom) do
  begin
    try s2 := sl1.Strings[y+1]; except end;
    sn := '';
    try s1 := sl1.Strings[y]; except end;
    try s3 := sl1.strings[y+2]; except end;
    //Spalten
    try for x := 0 to Length(sl1.strings[y])-1 do
    begin
      i := 0;
      //-Oben-
      try if (Copy(s1,x,1) = '1') then inc(i); except end;

      try if (Copy(s1,x+1,1) = '1') then inc(i); except end;

      try if (Copy(s1,x+2,1) = '1') then inc(i); except end;

      //-Mitte-
      try if (Copy(s2,x,1) = '1') then inc(i); except end;

      try if Copy(s2,x+2,1) = '1then inc(i); except end;

      //-Unten-
      try if (Copy(s3,x,1) = '1') then inc(i); except end;

      try if (Copy(s3,x+1,1) = '1') then inc(i); except end;

      try if Copy(s3,x+2,1) = '1then inc(i); except end;

      //-Setzen-
      if (i = 3) then sn := sn + '1';

      if (i = 2) and (Copy(s2, x+1,1) = '1') then sn := sn + '1';

      if (i = 2) and (Copy(s2, x+1,1) = '0') then sn := sn + '0';

      if (i <> 2) then if (i <> 3) then sn := sn + '0';

      sl2.Strings[y] := sn;
    end; except end;
  end;
  inc (z);
  for w := 0 to round(self.width / zoom) do
  begin
    Insert('0', strings, 0);
  end;
  sl1.Insert (0,strings);
  sl1 := sl2;
  for n2 := 0 to sl1.Count-1 do
  begin
    for n := 0 to Length(sl1.strings[n2])+z do
    begin
      if Copy(sl1.strings[n2],n,1) = '1then Canvas.Brush.Color := clYellow else
        Canvas.Brush.Color := clGray;
      Canvas.Rectangle(n*zoom, (n2+1)*zoom, n*zoom+zoom, (n2+1)*zoom+zoom);
    end;
  end;
end;
  Mit Zitat antworten Zitat