tic tac toe in pascal --> a problem occurred
- by Emese
I don't know why my program doesn't run. I would really appreciate your help. Here's my program:
USES graph,crt;
type tegla=record
x,y:integer;
ertek:0..2;
end;
var gd,gm:integer; i,j:integer; c:char; jatekos:integer;
a:array[1..3,1..3]of tegla;
lx,ly:integer;
procedure tabla;
var x,y,i,j:integer;
begin
lx:=getmaxx div 3;
ly:=getmaxy div 3;
for i:=1 to 3 do begin
y:=(i-1)*ly;
for j:=1 to 3 do begin
x:=(j-1)*lx;
a[i,j].x:=x;
a[i,j].y:=y;
a[i,j].ertek:=0;
setbkcolor(10);
setcolor(9);
rectangle(a[i,j].x,a[i,j].y,a[i,j].x+lx,a[i,j].y+ly);
end;
end;
end;
procedure aktival(i,j:integer);
begin
setcolor(red);
rectangle(a[i,j].x,a[i,j].y,a[i,j].x+lx,a[i,j].y+ly);
end;
procedure visszaallit(i,j:integer);
begin
setcolor(9);
rectangle(a[i,j].x,a[i,j].y,a[i,j].x+lx,a[i,j].y+ly);
end;
procedure rajzolx(i,j:integer);
begin
setcolor(5);
line(a[i,j].x,a[i,j].y,a[i,j].x+lx,a[i,j].y+ly);
line(a[i,j].x+lx,a[i,j].y,a[i,j].x,a[i,j].y+ly);
end;
procedure rajzol_0(i,j:integer);
begin
setcolor(13);
circle(a[i,j].x+lx div 2, a[i,j].y+ly div 2, 50);
end;
procedure kinyer(i,j:integer);
begin
jatekos:=1;
if a[1,1]=a[2,2] and a[3,3]=a[1,1] and a[2,2]=a[3,3] or a[3,1]=a[2,2] and a[1,3]=a[3,1] and a[1,3]=a[2,2] then
if jatekos then begin cleardevice;
writeln('x nyert!');
end
else if jatekos+1 then begin cleardevice;
writeln('O nyert!');
end
else for i:=1 to 3 do begin
if a[i,1]=a[i,2] and a[i,1]=a[i,3] and a[i,2]=a[i,3] or a[1,i]=a[2,i] and a[1,i]=a[3,i] and a[2,i]=a[3,i] then if jatekos then begin cleardevice;
writeln('x nyert');
end
else if jatekos+1 then begin cleardevice;
writeln('O nyert!');
end;
end;
Begin
initgraph(gd,gm,' ');
tabla;
jatekos:=1;
i:=2;
j:=2;
aktival(i,j);
repeat
c:=readkey;
if ord(c)=0 then begin
c:=readkey;
case ord(c)of
72: if i>1 then begin visszaallit(i,j); dec(i); aktival(i,j);end;
77:if j<3 then begin visszaallit(i,j); inc(j); aktival(i,j); end;
80:if i<3 then begin visszaallit(i,j); inc(i); aktival(i,j); end;
75:if j>1 then begin visszaallit(i,j); dec(j); aktival(i,j); end;
end;
end;
if ord(c)=13 then begin
if a[i,j].ertek=0 then
if jatekos=1 then begin rajzolx(i,j);
a[i,j].ertek:=1;
jatekos:=2;
end
else begin rajzol_0(i,j);
a[i,j].ertek:=2;
jatekos:=1;
end;
end;
until ord(c)=27;
kinyer(i,j);
end;
end.
I hope you can help me. Thank you a lot!