program tanky;

var i:integer;
    x1,x2,a1,a2:integer;
    ox1,ox2:integer;
    key:char;
    kill1,kill2,flag:integer;
    sx1,sx2,sy1,sy2:integer;

procedure rect(x1,y1,x2,y2,c:integer);
begin
 draw(x1,y1,x2,y1,c);
 draw(x1,y1,x1,y2,c);
 draw(x1,y2,x2,y2,c);
 draw(x2,y1,x2,y2,c);
end;

procedure area;
begin
 rect(0,0,215,63,1);
end;

procedure tank(x,y,z,c:integer);
begin
 rect(x,y,x+10,y+7,c);
 rect(x+2,y+2,x+6,y+5,c);
 draw(x+4,y+4,x+4,y-z,c);
end;

procedure shot(var x1,y1,x2,y2:integer);
begin
 if y1>0 then
  begin
   draw(x1,y1,x1,y1+3,0);
   y1:=y1+6;
   draw(x1,y1,x1,y1+3,1);   
   if y1>61 then y1:=0;
  end;
 if y2<65 then
  begin
   draw(x2,y2,x2,y2+3,0);
   y2:=y2-6;
   draw(x2,y2,x2,y2+3,1);
   if y2<-3 then y2:=65;
  end;
end;

procedure killtest(x,y,sx,sy:integer; var f:integer);
begin
 if y<sy then
  if (x<sx) and (x+10>sx) then f:=1;
end;

procedure areatest(var x:integer);
begin
 if x<1 then x:=1;
 if x>204 then x:=204;
end;

procedure speedtest(var a1,a2:integer);
begin
 if a1>2 then a1:=2;
 if a1<-2 then a1:=-2;
 if a2>2 then a2:=2;
 if a2<-2 then a2:=-2;
end;

begin
 sx1:=0; sx2:=0; sy1:=0; sy2:=0;
 x1:=100;
 x2:=100;
 flag:=0;
 setmode(4);
 area;
 repeat
  shot(sx1,sy1,sx2,sy2);
  areatest(x1);
  areatest(x2);
  if ox1<> x1 then
    tank(ox1,1,-9,0);
  if ox2<>x2 then
    tank(ox2,55,2,0);
  tank(x1,1,-9,1);
  tank(x2,55,2,1);
  kill1:=0; kill2:=0; flag:=0;
  killtest(x1,sy2,sx2,8,kill1);
  killtest(x2,55,sx1,sy1,kill2);
  if kill1>0 then flag:=1;
  if kill2>0 then flag:=1;
  if keypressed then
   begin
    key:=inkey;
    case key of
     'z': a1:=a1-1;
     'x': a1:=a1+1;
     '.': a2:=a2-1;
     '/': a2:=a2+1;
     'e': flag:=1;
     'a': if sy1=0 then begin sy1:=9; sx1:=x1+4; end;
     ';': if sy2=65 then begin sy2:=50; sx2:=x2+4; end;
    end;
   end;
  speedtest(a1,a2);
  ox1:=x1; ox2:=x2;
  x1:=x1+a1;
  x2:=x2+a2;
 until flag<>0;
 setmode(7);
 if kill1>0 then writeln('Top tank was destroyed');
 if kill2>0 then writeln('Bottom tank was destroyed');
end.
