Uses Graph,Crt;
var Device,Mode,i,x,y,l,h1,h2,h3,h4,h5,h6,h7,h8,h9:integer;
    k:string;
Procedure mesto;
begin
if l mod 2=0 then begin
                  Line(x,y,x+60,y+60);
                  Line(x+60,y,x,y+60);
                  end
             else Circle(x,y,40);
l:=l+1;
end;

Procedure zalivka;
begin
SetFillStyle(1,7);
FloodFill(1,1,14);
SetFillStyle(1,15);
FloodFill(1,1,14);
SetColor(7);
SetLineStyle(0,0,ThickWidth);
Rectangle(160,60,520,420);
SetLineStyle(1,0,ThickWidth);
SetColor(8);
x:=280;
for i:=1 to 2 do begin Line(x,60,x,420); x:=x+120; end;
y:=180;
for i:=1 to 2 do begin Line(160,y,520,y); y:=y+120; end;
l:=0;
SetColor(4);
SetLineStyle(0,0,ThickWidth);
end;

begin
Device:=0;
InitGraph(Device,Mode,'');
SetFillStyle(1,15);
FloodFill(1,1,14);
SetColor(1);
SetLineStyle(0,0,ThickWidth);
Rectangle(160,60,520,420);
SetLineStyle(1,0,ThickWidth);
SetColor(8);
x:=280;
for i:=1 to 2 do begin Line(x,60,x,420); x:=x+120; end;
y:=180;
for i:=1 to 2 do begin Line(160,y,520,y); y:=y+120; end;
l:=0;
SetColor(1);
SetTextStyle(7,0,4);
OutTextXY(165,430,'Крестики-нолики');
SetColor(4);
SetLineStyle(0,0,ThickWidth);
repeat
k:=ReadKey;
if k='7' then begin
              if l mod 2=0 then begin x:=190; y:=90;
                                end
                           else begin x:=220; y:=120;
                                end;
              h7:=1;
              end;
if k='8' then begin
              if l mod 2=0 then begin x:=310; y:=90;
                                end
                           else begin x:=340; y:=120;
                                end;
              h8:=1;
              end;
if k='9' then begin
              if l mod 2=0 then begin x:=430; y:=90;
                                end
                           else begin x:=460; y:=120;
                                end;
              h9:=1;
              end;
if k='4' then begin
              if l mod 2=0 then begin x:=190; y:=210;
                                end
                           else begin x:=220; y:=240;
                                end;
              h4:=1;
              end;
if k='5' then begin
              if l mod 2=0 then begin x:=310; y:=210;
                                end
                           else begin x:=340; y:=240;
                                end;
              h5:=1;
              end;
if k='6' then begin
              if l mod 2=0 then begin x:=430; y:=210;
                                end
                           else begin x:=460; y:=240;
                                end;
              h6:=1;
              end;
if k='1' then begin
              if l mod 2=0 then begin x:=190; y:=330;
                                end
                           else begin x:=220; y:=360;
                                end;
              h1:=1;
              end;
if k='2' then begin
              if l mod 2=0 then begin x:=310; y:=330;
                                end
                           else begin x:=340; y:=360;
                                end;
              h2:=1;
              end;
if k='3' then begin
              if l mod 2=0 then begin x:=430; y:=330;
                                end
                           else begin x:=460; y:=360;
                                end;
              h3:=1;
              end;
if (k='r') or (k='R') then zalivka
                      else mesto;
until k=#27;
CloseGraph;
end.