Witam, pierwszy post, także Witam Wszystkich :) Postanowiłem napisać grę saper w delhpi. Szukałem zarówno na forum jak i w google, ale nie znalazłem konkretnej odpowiedzi.
Stworzyłem funkcję która odpowiada za wyswietlanie tzw. pustych pól, myślę że każdy wie o co chodzi. Oto kod:
procedure TForm1.odkrywanie1(x,y: integer);
BEGIN
with StringGrid1 do begin
if tab[x,y]=0 then
BEGIN
Cells[x,y]:=IntToStr(tab[x,y]);
wsp[x,y]:=2;
if (x>0) and (y>0) then
BEGIN
Cells[x-1,y-1]:=IntToStr(tab[x-1,y-1]);
if wsp[x-1,y-1]<>2 then wsp[x-1,y-1]:=1;
if tab[x-1,y-1]=0 then tab3[x-1,y-1]:=1;
END;
if x>0 then
BEGIN
Cells[x-1,y]:=IntToStr(tab[x-1,y]);
if wsp[x-1,y]<>2 then wsp[x-1,y]:=1;
if tab[x-1,y]=0 then tab3[x-1,y]:=1;
END;
if (x>0) and (y<9) then
BEGIN
Cells[x-1,y+1]:=IntToStr(tab[x-1,y+1]);
if wsp[x-1,y+1]<>2 then wsp[x-1,y+1]:=1;
if tab[x-1,y+1]=0 then tab3[x-1,y+1]:=1;
END;
if y<9 then
BEGIN
Cells[x,y+1]:=IntToStr(tab[x,y+1]);
if wsp[x,y+1]<>2 then wsp[x,y+1]:=1;
if tab[x,y+1]=0 then tab3[x,y+1]:=1;
END;
if y>0 then BEGIN
Cells[x,y-1]:=IntToStr(tab[x,y-1]);
if wsp[x,y-1]<>2 then wsp[x,y-1]:=1;
if tab[x,y-1]=0 then tab3[x,y-1]:=1;
END;
if (x<9) and (y>0) then
BEGIN
Cells[x+1,y-1]:=IntToStr(tab[x+1,y-1]);
if wsp[x+1,y-1]<>2 then wsp[x+1,y-1]:=1;
if tab[x+1,y-1]=0 then tab3[x+1,y-1]:=1;
END;
if x<9 then
BEGIN
Cells[x+1,y]:=IntToStr(tab[x+1,y]);
if wsp[x+1,y]<>2 then wsp[x+1,y]:=1;
if tab[x+1,y]=0 then tab3[x+1,y]:=1;
END;
if (x<9) and (y<9) then
BEGIN
Cells[x+1,y+1]:=IntToStr(tab[x+1,y+1]);
if wsp[x+1,y+1]<>2 then wsp[x+1,y+1]:=1;
if tab[x+1,y+1]=0 then tab3[x+1,y+1]:=1;
END;
END;
END;
for i:=0 to 9 do
for j:=0 to 9 do
if (wsp[i,j]=1) and (tab3[i,j]=1) then
odkrywanie1(i,j);
end;
Działanie polega mniej i więcej tak: Mam 3 tablice. Tab przechowuje całą planszę, wsp: przechowują wartość 0 lub 1 lub 2. dla 0 wartość nie wyświetlona, dla 1 wartość wyświetlona, dla 2 wartość wyświetlona i sprawdzona pod kątem pustego pola(Brak bomb wokół nich = wartość 0 ). Oraz tab3 która przechowuje wartość 1 dla pól które zostały wyświetlone i zawierają pola puste(wartość 0). na końcu w dwóch pętlach funkcja sprawdza czy są pola wyświetlone które zawierają puste pole czyli wsp = 1 i tab3=1;
Problem polega na tym że funkcja sie zapętla i wyskakuje błąd...
Proszę o pomoc