Далее в таймере формы мы пишем следующий код: //prorisovka karti for i:=0 to 9 do for j:=0 to 9 do buf.Canvas.Draw(i*60,j*60,Textures[ map[i,j] ]);
//prorisovka flagov komand buf.Canvas.Draw(flag[1].x*60,flag[1].y*60,flag[1].pic); buf.Canvas.Draw(flag[2].x*60,flag[2].y*60,flag[2].pic);
//proverka animatsii tanka for j:=1 to 3 do if Tank[j].Go=true then begin if Tank[j].Anim=1 then Tank[j].Anim:=2 else Tank[j].Anim:=1; end;
//prorisovka tankov if Tank[1].Visible=true then buf.Canvas.Draw(Tank[1].x,Tank[1].y,Tanki[1,Tank[1].povorot,Tank[1].anim]); if Tank[2].Visible=true then buf.Canvas.Draw(Tank[2].x,Tank[2].y,Tanki[2,Tank[2].povorot,Tank[2].anim]); if Tank[3].Visible=true then buf.Canvas.Draw(Tank[3].x,Tank[3].y,Tanki[3,Tank[3].povorot,Tank[3].anim]); //proverka na vistrel tanka for j:=1 to 3 do if (Tank[j].Fight=true) and (Tank[j].Vistrelil=false) then begin for i:=1 to 20 do begin if (Puli[i].visible=false) and (Tank[j].Vistrelil=false) then begin Puli[i].povorot:=Tank[j].Povorot; case Tank[j].Povorot of 1:begin Puli[i].x:=Tank[j].x; Puli[i].y:=Tank[j].y-37; Puli[i].visible:=true; Tank[j].Vistrelil:=true; end; 3:begin Puli[i].x:=Tank[j].x; Puli[i].y:=Tank[j].y+37; Puli[i].visible:=true; Tank[j].Vistrelil:=true; end; 2:begin Puli[i].x:=Tank[j].x+37; Puli[i].y:=Tank[j].y; Puli[i].visible:=true; Tank[j].Vistrelil:=true; end; 4:begin Puli[i].x:=Tank[j].x-37; Puli[i].y:=Tank[j].y; Puli[i].visible:=true; Tank[j].Vistrelil:=true; end; end; end; end; Tank[j].Zaderhka_Vistrela:=0; Tank[j].Fight:=false; end;
for j:=1 to 3 do if Tank[j].Vistrelil=true then begin if Tank[j].Zaderhka_Vistrela<=Tank[j].Max_vistrel then Tank[j].Zaderhka_Vistrela:=Tank[j].Zaderhka_Vistrela+1; if Tank[j].Zaderhka_Vistrela>Tank[j].Max_vistrel then Tank[j].Vistrelil:=false; end;
//prorisovka pul' for i:=1 to 20 do if Puli[i].visible=true then buf.Canvas.Draw(puli[i].x,puli[i].y,Pulya);
//izmeneniye koordinat pul for i:=1 to 20 do if puli[i].visible=true then begin case puli[i].povorot of 1:Puli[i].y:=Puli[i].y-puli[i].speed; 3:Puli[i].y:=Puli[i].y+Puli[i].speed; 4:Puli[i].x:=Puli[i].x-puli[i].speed; 2:Puli[i].x:=Puli[i].x+Puli[i].speed; end; //esli puli vishli za granitsi if (puli[i].x+27<=0) or (puli[i].x+27>=570) or (puli[i].y+27<=0) or (puli[i].y+27>=570) or (map[trunc( (puli[i].x+27)/60),trunc( (puli[i].y+27)/60)]=3) then puli[i].visible:=false; //esli puli popali v kirpichi if (map[trunc( (puli[i].x+27)/60),trunc( (puli[i].y+27)/60)]=2) then begin map[trunc( (puli[i].x+27)/60),trunc( (puli[i].y+27)/60)]:=1; puli[i].visible:=false; end;
//esli popali v tank for j:=1 to 3 do begin if (puli[i].x+27>=Tank[j].x) and (puli[i].x+27<=Tank[j].x+59) and (puli[i].y+27>=Tank[j].y) and (puli[i].y+27<=Tank[j].y+59) and (Tank[j].Visible=true) then begin puli[i].visible:=false; Tank[j].Visible:=false; end; end;
end;
//izmeneniye koordinat tanka if Tank[1].Go=true then begin //vverh if (Tank[1].Povorot=1) and (map[trunc(Tank[1].x/60),trunc( (Tank[1].y-Tank[1].Speed)/60)]=1) and (map[trunc( (Tank[1].x+59) /60),trunc( (Tank[1].y-Tank[1].Speed)/60)]=1) and (Tank[1].y-Tank[1].Speed>=0) then Tank[1].y:=Tank[1].y-Tank[1].Speed; //vniz if (Tank[1].Povorot=3) and (map[trunc(Tank[1].x/60),trunc( (Tank[1].y+Tank[1].Speed+59)/60)]=1) and (map[trunc( (Tank[1].x+59) /60),trunc( (Tank[1].y+Tank[1].Speed+59)/60)]=1) and (Tank[1].y+Tank[1].Speed<=540) then Tank[1].y:=Tank[1].y+Tank[1].Speed; //vpravo if (Tank[1].Povorot=2) and (map[trunc( (Tank[1].x+Tank[1].Speed+59)/60),trunc(Tank[1].y/60)]=1) and (map[trunc( (Tank[1].x+Tank[1].Speed+59)/60),trunc( (Tank[1].y+59) /60)]=1) and (Tank[1].x+Tank[1].Speed<=540) then Tank[1].x:=Tank[1].x+Tank[1].Speed; //vlevo if (Tank[1].Povorot=4) and (map[trunc( (Tank[1].x-Tank[1].Speed)/60),trunc(Tank[1].y/60)]=1) and (map[trunc( (Tank[1].x-Tank[1].Speed)/60),trunc( (Tank[1].y+59) /60)]=1) and (Tank[1].x-Tank[1].Speed>=0) then Tank[1].x:=Tank[1].x-Tank[1].Speed; end;
form1.Canvas.Draw(0,0,buf);
//proverka na pobedu ili porazeniye if (( flag[1].x=trunc(Tank[1].x/60) ) and ( flag[1].y=trunc(Tank[1].y/60) )) or (Tank[1].Visible=false) then begin Timer1.Enabled:=false; qUp:=false; qDown:=false; qLeft:=false; qRight:=false; Tank[1].x:=60; Tank[1].y:=540; Tank[1].Go:=false; if Tank[1].Visible=true then showmessage('ТУР Пройден!!!!'); if Tank[1].Visible=false then showmessage('Игра окончена!!!!'); //generirovaniye karti randomize; for i:=0 to 9 do for j:=0 to 9 do begin map[i,j]:=random(100)+1; if map[i,j]<=50 then map[i,j]:=1; if (map[i,j]>50) and (map[i,j]<=80) then map[i,j]:=2; if (map[i,j]>80) and (map[i,j]<=100) then map[i,j]:=3; end; //rasstanovka flagov i tankov map[9,0]:=1; map[9,1]:=1; map[8,0]:=1; map[0,9]:=1; map[0,8]:=1; map[trunc(Tank[1].x/60),trunc(Tank[1].y/60)]:=1;
//iskustvenniy intellekt 3 tanka //proverka na tank igroka ryadom if ( (trunc(Tank[1].x/60)=trunc(Tank[3].x/60)) and (Tank[3].visible=true)) or ( (trunc(Tank[1].y/60)=trunc(Tank[3].y/60)) and (Tank[3].visible=true)) then begin if trunc(Tank[1].x/60)<trunc(Tank[3].x/60) then Tank[3].Povorot:=4; if trunc(Tank[1].x/60)>trunc(Tank[3].x/60) then Tank[3].Povorot:=2; if trunc(Tank[1].y/60)<trunc(Tank[3].y/60) then Tank[3].Povorot:=1; if trunc(Tank[1].y/60)>trunc(Tank[3].y/60) then Tank[3].Povorot:=3; Tank[3].fight:=true; Tank[3].poyehal:=true; end;
//vlevo ehat if ( trunc(tank[3].x/60)>trunc(tank[1].x/60) ) and (Tank[3].poyehal=false) and (map[trunc( (Tank[3].x-Tank[3].Speed)/60),trunc(Tank[3].y/60)]=1) and (map[trunc( (Tank[3].x-Tank[3].Speed)/60),trunc( (Tank[3].y+59)/60)]=1) then begin Tank[3].x:=Tank[3].x-Tank[3].Speed; Tank[3].poyehal:=true; Tank[3].Povorot:=4; end; //vpravo ehat if ( trunc(tank[3].x/60)<trunc(tank[1].x/60) ) and (Tank[3].poyehal=false) and (map[trunc( (Tank[3].x+Tank[3].Speed+59)/60),trunc(Tank[3].y/60)]=1) and (map[trunc( (Tank[3].x+Tank[3].Speed+59)/60),trunc( (Tank[3].y+59)/60)]=1) then begin Tank[3].x:=Tank[3].x+Tank[3].Speed; Tank[3].poyehal:=true; Tank[3].Povorot:=2; end; //vniz ehat if ( trunc(tank[3].y/60)<trunc(tank[1].y/60) ) and (Tank[3].poyehal=false) and (map[trunc( Tank[3].x/60),trunc( (Tank[3].y+Tank[3].Speed+59)/60)]=1) and (map[trunc( (Tank[3].x+59)/60),trunc( (Tank[3].y+Tank[3].Speed+59)/60)]=1) then begin Tank[3].y:=Tank[3].y+Tank[3].Speed; Tank[3].poyehal:=true; Tank[3].Povorot:=3; end; //vverh ehat if ( trunc(tank[3].y/60)>trunc(tank[1].y/60) ) and (Tank[3].poyehal=false) and (map[trunc( Tank[3].x/60),trunc( (Tank[3].y-Tank[3].Speed)/60)]=1) and (map[trunc( (Tank[3].x+59)/60),trunc( (Tank[3].y-Tank[3].Speed)/60)]=1) then begin Tank[3].y:=Tank[3].y-Tank[3].Speed; Tank[3].poyehal:=true; Tank[3].Povorot:=1; end;
//proverka na kirpichi ryadom //sverhu if (Tank[3].vistrelil=false) and (map[trunc(Tank[3].x/60),trunc(Tank[3].y/60)-1]=2) and (Tank[3].visible=true) and (Tank[3].fight=false) then begin Tank[3].Fight:=true; Tank[3].Povorot:=1; end; //snizu if (Tank[3].vistrelil=false) and (map[trunc(Tank[3].x/60),trunc(Tank[3].y/60)+1]=2) and (Tank[3].visible=true) and (Tank[3].fight=false) then begin Tank[3].Fight:=true; Tank[3].Povorot:=3; end; //sprava if (Tank[3].vistrelil=false) and (map[trunc(Tank[3].x/60)+1,trunc(Tank[3].y/60)]=2) and (Tank[3].visible=true) and (Tank[3].fight=false) then begin Tank[3].Fight:=true; Tank[3].Povorot:=2; end; //sleva if (Tank[3].vistrelil=false) and (map[trunc(Tank[3].x/60)-1,trunc(Tank[3].y/60)]=2) and (Tank[3].visible=true) and (Tank[3].fight=false) then begin Tank[3].Fight:=true; Tank[3].Povorot:=4; end;
//isskustvenniy intellekt 2 tanka if (trunc(Tank[1].x/60)=trunc(Tank[2].x/60)) or (trunc(Tank[1].y/60)=trunc(Tank[2].y/60)) then begin if trunc(Tank[1].x/60)<trunc(Tank[2].x/60) then Tank[2].Povorot:=4; if trunc(Tank[1].x/60)>trunc(Tank[2].x/60) then Tank[2].Povorot:=2; if trunc(Tank[1].y/60)<trunc(Tank[2].y/60) then Tank[2].Povorot:=1; if trunc(Tank[1].y/60)>trunc(Tank[2].y/60) then Tank[2].Povorot:=3; Tank[2].fight:=true; Tank[2].poyehal:=true; end;
if (tank[2].poyehal=false) and (Tank[2].fight=false) then begin randomize; Tank[2].Povorot:=random(4)+1; if Tank[2].Povorot=1 then begin if (trunc( (Tank[2].y-Tank[2].Speed) /60)>=1) and (map[trunc( Tank[2].x /60),trunc( (Tank[2].y-Tank[2].Speed) /60)]=1) and (map[trunc( (Tank[2].x+59) /60),trunc( (Tank[2].y-Tank[2].Speed) /60)]=1) then Tank[2].y:=Tank[2].y-Tank[2].speed;
if (trunc( (Tank[2].y-Tank[2].Speed) /60)>=1) and (map[trunc( Tank[2].x /60),trunc( (Tank[2].y-Tank[2].Speed) /60)]>1) and (map[trunc( (Tank[2].x+59) /60),trunc( (Tank[2].y-Tank[2].Speed) /60)]>1) then Tank[2].fight:=true; end;
if Tank[2].Povorot=3 then begin if (trunc( (Tank[2].y+Tank[2].Speed) /60)<=9) and (map[trunc( Tank[2].x /60),trunc( (Tank[2].y+Tank[2].Speed+59) /60)]=1) and (map[trunc( (Tank[2].x+59) /60),trunc( (Tank[2].y+Tank[2].Speed+59) /60)]=1) then Tank[2].y:=Tank[2].y+Tank[2].speed;
if (trunc( (Tank[2].y+Tank[2].Speed) /60)<=9) and (map[trunc( Tank[2].x /60),trunc( (Tank[2].y+Tank[2].Speed+59) /60)]>1) and (map[trunc( (Tank[2].x+59) /60),trunc( (Tank[2].y+Tank[2].Speed+59) /60)]>1) then Tank[2].fight:=true; end;
if Tank[2].Povorot=4 then begin if (trunc( (Tank[2].x-Tank[2].Speed) /60)>=0) and (map[trunc( (Tank[2].x-Tank[2].Speed) /60),trunc(Tank[2].y/60)]=1) and (map[trunc( (Tank[2].x-Tank[2].Speed) /60),trunc( (Tank[2].y+59)/60)]=1) then Tank[2].x:=Tank[2].x-Tank[2].speed;
if (trunc( (Tank[2].x-Tank[2].Speed) /60)>=0) and (map[trunc( (Tank[2].x-Tank[2].Speed) /60),trunc(Tank[2].y/60)]>1) and (map[trunc( (Tank[2].x-Tank[2].Speed) /60),trunc( (Tank[2].y+59)/60)]>1) then Tank[2].fight:=true; end;
if Tank[2].Povorot=2 then begin if (trunc( (Tank[2].x+Tank[2].Speed) /60)<=9) and (map[trunc( (Tank[2].x+Tank[2].Speed+59) /60),trunc(Tank[2].y/60)]=1) and (map[trunc( (Tank[2].x+Tank[2].Speed+59) /60),trunc( (Tank[2].y+59)/60)]=1) then Tank[2].x:=Tank[2].x+Tank[2].speed;
if (trunc( (Tank[2].x+Tank[2].Speed) /60)<=9) and (map[trunc( (Tank[2].x+Tank[2].Speed+59) /60),trunc(Tank[2].y/60)]>1) and (map[trunc( (Tank[2].x+Tank[2].Speed+59) /60),trunc( (Tank[2].y+59)/60)]>1) then Tank[2].fight:=true; end;