Program galo; uses crt; const nl = #13+#10; type mtx33 = array[0..2,0..2] of byte; var i,j,key,jgd,cwin,win,njg:smallint; game: mtx33; procedure drawgame; begin clrscr; gotoxy(33,1); writeln('Jogo do Galo'); gotoxy(1,3); writeln('Instrucoes:',nl); writeln(' 7 | 8 | 9 '); writeln('-----------'); writeln(' 4 | 5 | 6 '); writeln('-----------'); writeln(' 1 | 2 | 3 '); gotoxy(31,5); writeln(' | | '); gotoxy(31,6); writeln('-----------------'); gotoxy(31,7); writeln(' | | '); gotoxy(31,8); writeln('-----------------'); gotoxy(31,9); writeln(' | | '); for i:=0 to 2 do for j:=0 to 2 do begin gotoxy(33+6*i,9-2*j); if game[i,j]=1 then write('X') else if game[i,j]=2 then write('O'); end; end; Begin njg:=0; win:=0; clrscr; jgd:=2; for i:=0 to 2 do for j:=0 to 2 do game[i,j]:=0; drawgame; repeat jgd:=3-jgd; // toggle jog1/2 gotoxy(1,12); write('Jogador ',jgd,nl,'> '); repeat gotoxy(2,13); readln(key); j:=(key-1) div 3; i:=(key-1) mod 3; until game[i,j]=0; if (i<3) and (j<3) then game[i,j]:=jgd; // verificação de vitoria // vertical for i:=0 to 2 do begin cwin:=0; for j:=0 to 2 do if game[i,j]=jgd then cwin:=cwin+1; if cwin=3 then win:=1; end; // horizontal for j:=0 to 2 do begin cwin:=0; for i:=0 to 2 do if game[i,j]=jgd then cwin:=cwin+1; if cwin=3 then win:=1; end; // diagonal coordenadas iguais cwin:=0; for i:=0 to 2 do if game[i,i]=jgd then cwin:=cwin+1; if cwin=3 then win:=1; // diagonal coordenadas opostas cwin:=0; for i:=0 to 2 do if game[2-i,i]=jgd then cwin:=cwin+1; if cwin=3 then win:=1; //empate njg:=njg+1; if njg=9 then win:=2; drawgame; until win>0; gotoxy(2,15); if win=1 then write('Jogador ',jgd,' ganha!') else write('Empate!'); readln; end.