program ZA4etka; Uses Graph,CRT,cubes,dos; const nn=15;kk=3; type mas=array[1..nn] of ppoint; type maz=array[1..kk] of ppoint; Var Gd, Gm, a,b,xx,yy,z: Integer; ll:maz; mm:mas; ch:char; cubb:pcube; {***************************LEFT!!!**************************} procedure checkleft(var m:mas;var l:maz;n,k:integer; var cub:pcube); var i,j,v:integer; f,f1:boolean; a1,b1,a2,b2:integer; begin F:=false; f1:=false; i:=1; j:=1; cub^.getxy(a1,b1); if (a1 > 120) then {main wall?} while (f=false) or (i <= n) do {wall?} begin m[i]^.getxy(a2,b2); if (a2=a1-41) and (b1=b2) then f:=true; i:=i+1; end; if f=false then while (f1=false) or (j <= k) do {box?} begin l[j]^.getxy(a2,b2); if (a2=a1-41) and (b1=b2) and (a2 > 120)then f1:=true;v:=j; j:=j+1; end; i:=1; if f1=true then while (f=false) or (i <= n) do {wall undo box} begin m[i]^.getxy(a2,b2); if (a2=a1-82) and (b1=b2) then f:=true; i:=i+1; end; if (f=false) and (f1=false) then cub^.move(-41,0); if (f=true) and (f1=true)then begin l[v]^.move(-41,0); cub^.move(-41,0); end; end; {***************************RIGHT!!!**************************} procedure checkright(var m:mas;var l:maz;n,k:integer;var cub:pcube); var i,j,v:integer; f,f1:boolean; a1,b1,a2,b2:integer; begin i:=1; j:=1; F:=false; f1:=false; cub^.getxy(a1,b1); if (a1 < 480) then {main wall?} while (f=false) or (i <= n) do{wall?} begin m[i]^.getxy(a2,b2); if (a2=a1+41) and (b1=b2) then f:=true; i:=i+1; end; if f=false then while (f1=false) or (j <= k) do{box?} begin l[j]^.getxy(a2,b2); if (a2=a1+41) and (b1=b2) and (a2 < 480)then f1:=true;v:=j; j:=j+1; end; i:=1; if f1=true then while (f=false) or (i <= n) do{wall undo box?} begin m[i]^.getxy(a2,b2); if (a2=a1+82) and (b1=b2) then f:=true; i:=i+1; end; if f=false then cub^.move(41,0); if (f=true) and (f1=true)then begin l[v]^.move(41,0); cub^.move(41,0); end; end; {***************************UP!!!**************************} procedure checkup(var m:mas;var l:maz;n,k:integer;var cub:pcube); var i,j,v:integer; f,f1:boolean; a1,b1,a2,b2:integer; begin i:=1; j:=1; F:=false; f1:=false; cub^.getxy(a1,b1); if (b1 > 40) then {main wall?} while (f=false) or (i <= n) do {wall?} begin m[i]^.getxy(a2,b2); if (b2=b1-41) and (a1=a2) then f:=true; i:=i+1; end; if f=false then while (f1=false) or (j <= k) do {box?} begin l[j]^.getxy(a2,b2); if (b2=b1-41) and (a1=a2) and (b2 > 40)then f1:=true;v:=j; j:=j+1; end; i:=1; if f1=true then while (f=false) or (i <= n) do {wall undo box?} begin m[i]^.getxy(a2,b2); if (b2=b1-82) and (a1=a2) then f:=true; i:=i+1; end; if f=false then cub^.move(0,-41); if (f=true) and (f1=true)then begin l[v]^.move(0,-41); cub^.move(0,-41); end; end; {***************************DOWN!!!**************************} procedure checkdown(var m:mas;var l:maz;n,k:integer;var cub:pcube); var i,j,v:integer; f,f1:boolean; a1,b1,a2,b2:integer; begin i:=1; j:=1; F:=false; f1:=false; cub^.getxy(a1,b1); if (b1 < 400) then {main wall?} while (f=false) or (i <= n) do {wall?} begin m[i]^.getxy(a2,b2); if (b2=b1+41) and (a1=a2) then f:=true; i:=i+1; end; if f=false then while (f1=false) or (j <= k) do {box?} begin l[j]^.getxy(a2,b2); if (b2=b1+41) and (a1=a2) and (b2 < 400)then f1:=true;v:=j; j:=j+1; end; i:=1; if f1=true then while (f=false) or (i <= n) do {wall undo box?} begin m[i]^.getxy(a2,b2); if (b2=b1+82) and (a1=a2) then f:=true; i:=i+1; end; if f=false then cub^.move(0,41); if (f=true) and (f1=true)then begin l[v]^.move(0,41); cub^.move(0,41); end; end; {***************************PLACE!!!**************************} procedure placebo; var xx,yy:integer; begin xx:=120; yy:=40; setfillstyle(1,6); bar(xx-4,yy-4,xx+413,yy+413); setfillstyle(1,7); bar(xx,yy,xx+409,yy+409); end; {***************************BEGIN!!!**************************} Begin Gd:=Detect; InitGraph(Gd, Gm, 'C:\Downloads\Muse\tp7\tp7\BGI'); If GraphResult <> grOk Then Halt(1); placebo; cubb:=new(pcube,init(120,40)); mM[1]:=new(pwall,init(120,163)); mM[2]:=new(pwall,init(120,204)); mM[3]:=new(pwall,init(120,245)); mM[4]:=new(pwall,init(120,286)); mM[5]:=new(pwall,init(161,286)); mM[6]:=new(pwall,init(202,163)); mM[7]:=new(pwall,init(243,204)); mM[8]:=new(pwall,init(284,245)); mM[9]:=new(pwall,init(325,286)); mM[10]:=new(pwall,init(161,245)); mM[11]:=new(pwall,init(120,245)); mM[12]:=new(pwall,init(120,286)); mM[13]:=new(pwall,init(161,286)); mM[14]:=new(pwall,init(325,245)); mM[15]:=new(pwall,init(366,286)); ll[1]:=new(pbox,init(120,122)); ll[2]:=new(pbox,init(407,204)); ll[3]:=new(pbox,init(407,245)); mM[1]^.switchon; mM[2]^.switchon; mM[3]^.switchon; mM[4]^.switchon; mM[5]^.switchon; mM[6]^.switchon; mM[7]^.switchon; mM[8]^.switchon; mM[9]^.switchon; mM[10]^.switchon; mM[11]^.switchon; mM[12]^.switchon; mM[13]^.switchon; mM[14]^.switchon; mM[15]^.switchon; cubb^.switchon; repeat ll[1]^.switchon; ll[2]^.switchon; ll[3]^.switchon; ch:=readkey; case ch of chr(75):begin checkleft(mm,ll,nn,kk,cubb); end; chr(77):begin checkright(mm,ll,nn,kk,cubb); end; chr(72):begin checkup(mm,ll,nn,kk,cubb); end; chr(80):begin checkdown(mm,ll,nn,kk,cubb); end; end; until ch=chr(27); CloseGraph; End. |