Einzelnen Beitrag anzeigen

Benutzerbild von Daniela.S
Daniela.S

Registriert seit: 1. Mär 2008
Ort: Niederösterreich
224 Beiträge
 
Delphi XE4 Enterprise
 
#24

AW: Game Of Life - ich könnte etwas Hilfe gebrauchen, bitte

  Alt 15. Jun 2011, 18:43
letzte Nachbarzelle...

Delphi-Quellcode:
function GameOfLife(x,y: Integer): Integer;
var Temp: Integer;
begin
  Temp:=0;
  if (x>1) and (y>1) and (Zellen[x-1,y-1]=1) then Temp:=Temp+1;
  if (y>1) and (Zellen[x,y-1]=1) then Temp:=Temp+1;
  if (x<4) and (y>1) and (Zellen[x+1,y-1]=1) then Temp:=Temp+1;

  if (x>1) and (Zellen[x-1,y]=1) then Temp:=Temp+1;
  if (x<4) and (Zellen[x+1,y]=1) then Temp:=Temp+1;

  if (x>1) and (y<4) and (Zellen[x-1,y+1]=1) then Temp:=Temp+1;
  if (y<4) and (Zellen[x,y+1]=1) then Temp:=Temp+1;
  if (x<4) and (y<4) and (Zellen[x+1,y+1]=1) then Temp:=Temp+1; // <----x<4

  case Temp of
  0,1,4..8: Result:=0;
  2: if (Zellen[x,y]=1) then Result:=1 else Result:=0;
  3: Result:=1;
  end;
end;
  Mit Zitat antworten Zitat