Próbuje ostatnio zrobić tą gre. na razie wszystko fajnie wychodziło ale mam problem nad sprawdzaniem czy statek jest zatopiony lub czy jest dobrze ustawiony (czodzi chyba o to aby program sprawdzał ile czarnych paneli ze sobą sąsiaduje). (MAM 100 PANELI o nazwach od "my1' do "my100".
To moje próby:
var
i, i2: Integer;
Sprawdzone: TStringList;
Akt: TComponent;
OK: Boolean;
begin
Sprawdzone:=TStringList.Create;
Maszty:=1;
for i:=1 to 100 do
begin
Akt:=FindComponent('my'+IntToStr(i));
if (TPanel(Akt).Color=clBlack) and (Pos(IntToStr(i), Sprawdzone.Text)=0) then
begin
OK:=False;
i2:=i;
repeat
i2:=i2+10;
Akt:=FindComponent('my'+IntToStr(i2));
if TPanel(Akt).Color=clBlack then
begin
OK:=True;
Sprawdzone.Add(IntToStr(i2));
Maszty:=Maszty+1;
end else OK:=False;
until OK=False;
i2:=i;
repeat
i2:=i2-10;
Akt:=FindComponent('my'+IntToStr(i2));
if TPanel(Akt).Color=clBlack then
begin
OK:=True;
Sprawdzone.Add(IntToStr(i2));
Maszty:=Maszty+1;
end else OK:=False;
until OK=False;
i2:=i;
repeat
i2:=i2+1;
Akt:=FindComponent('my'+IntToStr(i2));
if TPanel(Akt).Color=clBlack then
begin
OK:=True;
Sprawdzone.Add(IntToStr(i2));
Maszty:=Maszty+1;
end else OK:=False;
until OK=False;
i2:=i;
repeat
i2:=i2-1;
Akt:=FindComponent('my'+IntToStr(i2));
if TPanel(Akt).Color=clBlack then
begin
OK:=True;
Sprawdzone.Add(IntToStr(i2));
Maszty:=Maszty+1;
end else OK:=False;
until OK=False;
i2:=i;
repeat
i2:=i2-9;
Akt:=FindComponent('my'+IntToStr(i2));
if TPanel(Akt).Color=clBlack then
begin
OK:=True;
Sprawdzone.Add(IntToStr(i2));
Maszty:=Maszty+1;
end else OK:=False;
until OK=False;
i2:=i;
repeat
i2:=i2+11;
Akt:=FindComponent('my'+IntToStr(i2));
if TPanel(Akt).Color=clBlack then
begin
OK:=True;
Sprawdzone.Add(IntToStr(i2));
Maszty:=Maszty+1;
end else OK:=False;
until OK=False;
i2:=i;
repeat
i2:=i2-11;
Akt:=FindComponent('my'+IntToStr(i2));
if TPanel(Akt).Color=clBlack then
begin
OK:=True;
Sprawdzone.Add(IntToStr(i2));
Maszty:=Maszty+1;
end else OK:=False;
until OK=False;
i2:=i;
repeat
i2:=i2+9;
Akt:=FindComponent('my'+IntToStr(i2));
if TPanel(Akt).Color=clBlack then
begin
OK:=True;
Sprawdzone.Add(IntToStr(i2));
Maszty:=Maszty+1;
end else OK:=False;
until OK=False;
i2:=i2-19;
Akt:=FindComponent('my'+IntToStr(i2));
if TPanel(Akt).Color=clBlack then
begin
OK:=True;
Sprawdzone.Add(IntToStr(i2));
Maszty:=Maszty+1;
end;
Memo1.Lines.Add(IntToStr(Maszty));
Maszty:=1;
end;
end;
Sprawdzone.Free;
i to działa nawet fajnie tylko lest problem jeśli czteromasztowiec będzie w kaształcie litery "L".
var
i: Integer;
Sprawdzone: TStringList;
Akt: TComponent;
OK: Boolean;
begin
Sprawdzone:=TStringList.Create;
Maszty:=0;
for i:=1 to 100 do
begin
Akt:=FindComponent('my'+IntToStr(i));
if TPanel(Akt).Color=clBlack then
begin
OK:=False;
Akt:=FindComponent('my'+IntToStr(i+10));
if (TPanel(Akt).Color=clBlack) and (Pos(IntToStr(i+10), Sprawdzone.Text)=0) then
begin
OK:=True;
Sprawdzone.Add(IntToStr(i+10));
Maszty:=Maszty+1;
end;
Akt:=FindComponent('my'+IntToStr(i-10));
if (TPanel(Akt).Color=clBlack) and (Pos(IntToStr(i-10), Sprawdzone.Text)=0) then
begin
OK:=True;
Sprawdzone.Add(IntToStr(i-10));
Maszty:=Maszty+1;
end;
Akt:=FindComponent('my'+IntToStr(i+1));
if (TPanel(Akt).Color=clBlack) and (Pos(IntToStr(i+1), Sprawdzone.Text)=0) then
begin
OK:=True;
Sprawdzone.Add(IntToStr(i+1));
Maszty:=Maszty+1;
end;
Akt:=FindComponent('my'+IntToStr(i-1));
if (TPanel(Akt).Color=clBlack) and (Pos(IntToStr(i-1), Sprawdzone.Text)=0) then
begin
OK:=True;
Sprawdzone.Add(IntToStr(i-1));
Maszty:=Maszty+1;
end;
if OK=False then
begin
ShowMessage(IntToStr(Maszty));
Maszty:=0;
end;
end;
end;
Sprawdzone.Free;
A tu znowu wykrywa statek idealnie ale tylko gdy jest jeden :) Gdy są dwa to mu sie coś je*** :)
--Delphi 6 Personal