Make your own free website on Tripod.com

program good_game;
uses wincrt;
var
name1, name2 : string;
game : array[1..3, 1..3] of char;
I, J, count, row, column : integer;
find : boolean;
procedure get_data;
begin
for I := 1 to 3 do
for J := 1 to 3 do
game[I, J] := ' ';
count := 1;
write('Enter the name of first player : ');
readln(name1);
write('Enter the name of second player : ');
readln(name2);
writeln(name1, ' uses X.');
writeln(name2, ' uses O.');
writeln('--- Game Start ---');
end;
procedure play;
begin
repeat
case (count mod 2) of
1 : write('Place of X : ');
0 : write('Place of O : ')
end;
readln(row, column);
if (row < 1) or (row > 3) or (column < 1) or (column > 3) and (Game[row, column] <> ' ')
then writeln('Wrong data, reenter please !')
until (row >= 1) and (row <= 3) and (column >= 1) and (column <= 3) and (game[row, column] = ' ');
case (count mod 2) of
1 : game[row, column] := 'X';
0 : game[row, column] := 'O'
end;
count := count + 1
end;
procedure display;
begin
for I := 1 to 3 do
begin
for J := 1 to 3 do
write(game[I, J], ' ');
writeln(chr(7))
end
end;
procedure check;
begin
find := false;
for I := 1 to 3 do
begin
if (game[I, 1] = game[I, 2]) and (game[I, 2] = game[I, 3])
and (game[I, 1] <> ' ')
then begin
find := true;
I := 3;
if game[I, 1] = 'X'
then writeln(name1, ' wins!')
else writeln(name2, ' wins!')
end;
if (game[1, I] = game[2, I]) and (game[2, I] = game[3,I]) and (game[1, I] <> ' ')
then begin
find := true;
I := 3;
if game[1, I] = 'X'
then writeln(name1, ' wins!')
else writeln(name2, ' wins!')
end
end;
if find = false
then begin
if (game[1, 1] = game[2, 2]) and (game[2, 2] = game[3, 3]) and (game[1, 1] <> ' ')
then begin
find := true;
if game[1, 1] = 'X'
then writeln(name1, ' wins!')
else writeln(name2, ' wins!')
end;
end;
if find = false
then begin
if (game[1,3] = game[2, 2]) and (game[2, 2] = game[3, 1]) and (game[1, 3] <> ' ')
then begin
find := true;
if game[1, 3] = 'X'
then writeln(name1, ' wins!')
else writeln(name2, ' wins!')
end;
end;
end;
begin {Main Program}
get_data;
repeat
play;
display;
check
until find = true;
end.