RedCemetery
Newbie | Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору Люди, помогите разобрать программу: uses crt,graph; var A,B:array[0..51,0..31] of boolean; i,j,VP,step,live,dead,born:integer; s,stri:string; label 1; {****************************************} Procedure FlipVP(var P:integer); Begin SetVisualPage(P); P:=1-P; SetActivePage(p); ClearDevice; End; {****************************************} Function Nears(x,y:integer):integer; var i,j,s:integer; Begin s:=0; for i:=x-1 to x+1 do for j:=y-1 to y+1 do if a[i,j] then s:=s+1; if a[x,y] then s:=s-1; Nears:=s; End; {****************************************} Function Change:boolean; Begin born:=0; dead:=0; Change:=False; for i:=1 to 50 do for j:=1 to 30 do begin if A[i,j] then begin if ((Nears(i,j)<2) or (Nears(i,j)>3)) then begin B[i,j]:=false; dead:=dead+1; Change:=true; end; end else begin if Nears(i,j)=3 then begin B[i,j]:=true; born:=born+1; Change:=true; end; end; end; End; {****************************************} Procedure Setup; var i,j:integer; Begin Randomize; for i:=1 to 50 do for j:=1 to 30 do if Random(2)=0 then A[i,j]:=true; End; {****************************************} Procedure Draw; var i,j:integer; Begin Rectangle(0,0,639,349); for i:=0 to 51 do for j:=0 to 31 do begin if A[i,j] then SetFillStyle(1,10) else SetFillStyle(9,1); Bar(55+10*i,10+8*j,65+10*i,18+8*j); Rectangle(55+10*i,10+8*j,65+10*i,18+8*j); end; End; {****************************************} Procedure Copy; var i,j:integer; Begin for i:=1 to 50 do for j:=1 to 30 do A[i,j]:=B[i,j]; End; {****************************************} Procedure Print; Begin Str(step:3,s); stri:='Step#'+s; Str(live:3,s); stri:=stri+' Cells '+s; outtextxy(55,300,stri); Str(born:3,s); stri:='Born'+s; Str(dead:3,s); stri:=stri+' Died'+s; outtextxy(55,315,stri); End; {****************************************} Procedure Count; var i,j:integer; Begin live:=0; for i:=1 to 50 do for j:=1 to 30 do if A[i,j] then live:=live+1; End; {****************************************} BEGIN Setup; i:=9; j:=1; InitGraph(i,j,'c:\bp\bin'); SetColor(9); While Change do begin step:=step+1; FlipVP(VP); Draw; Count; Print; Copy; Delay(22); if KeyPressed then if ReadKey<>'' then goto 1; end; 1: ReadKey; CloseGraph; ClrScr; END. Там понятно почти все, только я не поняла, как процедуры Setup и Count работают. Заранее благодарю. Кстати, программа игры "Жизнь" Конвея |