program the_end_is_the_beginning_is_the_end;
uses graph,crt;
type moje=(nic,stena,p1,p2);
var i,j,gd,gm,s,last1x,last1y,last2x,last2y,score1,score2:integer;
    pole:array[0..300,0..200] of moje;
    p2x,p2y,p1x,p1y,fi1,fi2,ot:real;
    key,meno1,meno2,sc1,sc2:string;
procedure score;
begin
settextstyle(2,0,6);
setcolor(15);
str(score1,sc1);
str(score2,sc2);
setviewport(10,410,getmaxx,430,true);clearviewport;
setviewport(0,0,getmaxx,getmaxy,true);
outtextXY(10,410,meno1+': '+sc1);
setcolor(green);
outtextXY(510,410,meno2+': '+sc2);
setviewport(0,0,getmaxx,getmaxy,true);
end;


begin
ot:=pi/2;
meno1:='Marecek';
meno2:='Mato';
score1:=0;
score2:=0;
gd:=detect;
initgraph(gd,gm,'d:\bp\bgi\');
repeat
cleardevice;
score;
for i:=0 to 300 do for j:=0 to 200 do begin
                                     if (i=0) or (i=300) or (j=0) or (j=200)
                                              then pole[i,j]:=stena
                                              else pole[i,j]:=nic
                                       end;
s:=2;setfillstyle(4,9);
bar(0,0,s*300,s*200);
randomize;
p1x:=100;p1y:=100;p2x:=200;p2y:=100;
fi1:=2*pi*random;fi2:=1;
repeat
  if keypressed then key:=readkey
                 else key:='non';
  pole[round(p1x),round(p1y)]:=p1;
  pole[round(p2x),round(p2y)]:=p2;
  delay(20);
  setcolor(15);setfillstyle(1,15);
  fillellipse(round(s*p1x),round(s*p1y),2,2);
  setcolor(green);setfillstyle(1,green);
  fillellipse(round(s*p2x),round(s*p2y),2,2);
  if key='x' then fi1:=fi1+ot;
  if key='z' then fi1:=fi1-ot;
  if key='m' then fi2:=fi2+ot;
  if key='n' then fi2:=fi2-ot;
  p1x:=p1x+cos(fi1);p1y:=p1y+sin(fi1);
  p2x:=p2x+cos(fi2);p2y:=p2y+sin(fi2);
  if (round(p1x)=last1x) and (round(p1y)=last1y) then pole[last1x,last1y]:=nic;
  if (round(p2x)=last2x) and (round(p2y)=last2y) then pole[last2x,last2y]:=nic;
  last2x:=round(p2x);last2y:=round(p2y);
  last1x:=round(p1x);last1y:=round(p1y);
until (pole[round(p1x),round(p1y)]<>nic) or (key=char(27)) or (pole[round(p2x),round(p2y)]<>nic);
if key<>char(27) then begin
   if (pole[round(p1x),round(p1y)]<>nic) and (pole[round(p2x),round(p2y)]=nic) then score2:=score2+1;
   if (pole[round(p2x),round(p2y)]<>nic) and (pole[round(p1x),round(p1y)]=nic) then score1:=score1+1;
                      end;
score;
setcolor(12);
outtextxy(200,200,'Chces skoncit?[a/s]');
repeat
key:=readkey;
until (key='a') or (key='s')
until key='a';
end.