Kod:
program l4z3wer2;
{$APPTYPE CONSOLE}
uses
SysUtils;
var
tab:array[1..3,1..3] of string;
i,j,licznik:integer;
LABEL wroc;
LABEL wroc2;
LABEL pocz;
LABEL koniec;
begin
licznik:=0;
write('Kolko i krzyzyk, gra dla 2 osob');
writeln;
writeln;
for i:=1 to 3 do
begin
for j:=1 to 3 do
begin
tab[i,j]:='*';
write(tab[i,j]);
end;
writeln;
end;
pocz:
begin
writeln;
write('Gracz 1: O');
writeln;
writeln;
wroc:
repeat
write('Podaj nr wiersza: ');
readln(i);
until i in [1..3];
repeat
write('Podaj nr kolumny: ');
readln(j);
until j in [1..3];
writeln;
if (tab[i,j]='O') or (tab[i,j]='X') then
begin
writeln;
write('To pole juz jest zajete');
writeln;
goto wroc;
end;
tab[i,j]:='O';
licznik:=licznik+1;
for i:=1 to 3 do
begin
for j:=1 to 3 do
begin
write(tab[i,j]);
end;
writeln;
end;
end;
if (licznik=9) then
begin
writeln;
write('REMIS');
goto koniec;
end;
if (tab[1,1]='O') and (tab[1,2]='O') and (tab[1,3]='O') or // 1 wiersz
(tab[2,1]='O') and (tab[2,2]='O') and (tab[2,3]='O') or // 2 wiersz
(tab[3,1]='O') and (tab[3,2]='O') and (tab[3,3]='O') or // 3 wiersz
(tab[1,1]='O') and (tab[2,2]='O') and (tab[3,3]='O') or // 1 przekątkna
(tab[3,1]='O') and (tab[2,2]='O') and (tab[1,3]='O') or // 2 przekątna
(tab[1,1]='O') and (tab[2,1]='O') and (tab[3,1]='O') or // 1 kolumna
(tab[1,2]='O') and (tab[2,2]='O') and (tab[3,2]='O') or // 2 kolumna
(tab[1,3]='O') and (tab[2,3]='O') and (tab[3,3]='O') // 3 kolumna
then
begin
writeln;
write('Gracz 1 WYGRAL!!!');
goto koniec;
end
else
begin
writeln;
write('Gracz 2: X');
writeln;
writeln;
repeat
wroc2:
write('Podaj namiar x: ');
readln(i);
until i in [1..3];
repeat
write('Podaj namiar y: ');
readln(j);
until j in [1..3];
writeln;
if (tab[i,j]='O') or (tab[i,j]='X') then
begin
write('To pole juz jest zajete');
writeln;
goto wroc2;
end;
tab[i,j]:='X';
licznik:=licznik+1;
for i:=1 to 3 do
begin
for j:=1 to 3 do
begin
write(tab[i,j]);
end;
writeln;
end;
end;
if (tab[1,1]='X') and (tab[1,2]='X') and (tab[1,3]='X') or // 1 wiersz
(tab[2,1]='X') and (tab[2,2]='X') and (tab[2,3]='X') or // 2 wiersz
(tab[3,1]='X') and (tab[3,2]='X') and (tab[3,3]='X') or // 3 wiersz
(tab[1,1]='X') and (tab[2,2]='X') and (tab[3,3]='X') or // 1 przekątkna
(tab[3,1]='X') and (tab[2,2]='X') and (tab[1,3]='X') or // 2 przekątna
(tab[1,1]='X') and (tab[2,1]='X') and (tab[3,1]='X') or // 1 kolumna
(tab[1,2]='X') and (tab[2,2]='X') and (tab[3,2]='X') or // 2 kolumna
(tab[1,3]='X') and (tab[2,3]='X') and (tab[3,3]='X') // 3 kolumna
then
begin
writeln;
write('Gracz 2 WYGRAL!!!');
goto koniec;
end
else
goto pocz;
koniec:
readln;
end.
Znajdziesz nas na: