Ir ao conteúdo
  • Cadastre-se

Pascal jogo da velha repeat case if


Visitante: Lavanholi

Posts recomendados

Visitante: Lavanholi
 

Não consigo fazer a parte de escolha dos jogadores e das posições

Preciso de uma dica

program jvelha;
uses crt;
var a,b,d,e,f,g,h,i,x1,x2,f1,f2,f3,f4,f5,f6,f7,f8,f9,y1,y2:integer;
begin
clrscr;
write (' JOGO DA VELHA');
writeln;
writeln('Pressione 1 para X ou 0 para bolinha');
read(g);
Writeln(' 1§ jogador 2§ jogador');
x1:=10;
while x1 <40 do
BEGIN
gotoxy(x1,10);
write('_');
x1:=x1+1;
END;
x2:=10;
while x2 <40 do
BEGIN
gotoxy(x2,15);
write('_');
x2:=x2+1
END;
Y1:=7;
while Y1 <20 do
BEGIN
gotoxy(20,Y1);
write('|');
Y1:=Y1+1
END;
Y2:=7;
while Y2 <20 do
BEGIN
gotoxy(30,Y2);
write('|');
Y2:=Y2+1
END;
repeat
if d=0 then
begin
gotoxy(1,8);
write(' fa‡a sua jogada');
gotoxy(34,8);
write(' ');
d:=1;
e:=1;
end;
if(d=1) and (e=0) then
begin
gotoxy(34,8);
write('fa‡a sua jogada');
gotoxy(10,8);
write(' ');
d:=0;
end;
d:=0;
gotoxy(5,5);
read(f);
{1¦ jogada}
if(f=1) and (f1=0) then
begin
gotoxy(15,8);
if (g=1) and (h=0) then
begin
write ('X');
g:=0;
h:=1;
f1:=1;
end;
h:=0;
end;
{2§ jogada}
if(f=2) and (f2=0) then
begin
gotoxy(24,8);
if (g=1) and (h=0) then
begin
write ('X');
g:=0;
h:=1;
f2:=1;
end;
if (f=0) and (g=0) then
begin
write('O');
f:=1;
f2:=2;
end;
h:=0;
end;
{3¦ jogada}
if(f=3) and (f3=0) then
begin
gotoxy(36,8);
if (g=1) and (h=0) then
begin
write ('X');
g:=0;
h:=1;
f3:=1;
end;
if (f=0) and (g=0) then
begin
write('O');
f:=1;
f3:=2;
end;
h:=0;
end;
{ 4¦ jogada}
if(f=4) and (f4=0) then
begin
gotoxy(15,13);
if (g=1) and (h=0) then
begin
write ('X');
g:=0;
h:=1;
f4:=1;
end;
if (f=0) and (g=0) then
begin
write('O');
f:=1;
f4:=2;
end;
h:=0;
end;
{ 5¦ jogada}
if(f=5) and (f5=0) then
begin
gotoxy(24,13);
if (g=1) and (h=0) then
begin
write ('X');
g:=0;
h:=1;
f5:=1;
end;
if (f=0) and (g=0) then
begin
write('O');
f:=1;
f5:=2;
end;
h:=0;
end;
{ 6¦ jogada}
if(f=6) and (f6=0) then
begin
gotoxy(36,13);
if (g=1) and (h=0) then
begin
write ('X');
g:=0;
h:=1;
f6:=1;
end;
if (f=0) and (g=0) then
begin
write('O');
f:=1;
f6:=2;
end;
h:=0;
end;
{ 7¦ jogada}
if(f=7) and (f7=0) then
begin
gotoxy(15,18);
if (g=1) and (h=0) then
begin
write ('X');
g:=0;
h:=1;
f7:=1;
end;
if (f=0) and (g=0) then
begin
write('O');
f:=1;
f6:=2;
end;
h:=0;
end;
{8§ jogada}
if(f=8) and (f8=0) then
begin
gotoxy(24,18);
if (g=1) and (h=0) then
begin
write ('X');
g:=0;
h:=1;
f8:=1;
end;
if (f=0) and (g=0) then
begin
write('O');
f:=1;
f8:=2;
end;
h:=0;
end;
{9§ jogada}
if(f=9) and (f9=0) then
begin
gotoxy(36,18);
if (g=1) and (h=0) then
begin
write ('X');
g:=0;
h:=1;
f9:=1;
end;
if (f=0) and (g=0) then
begin
write('O');
f:=1;
f9:=2;
end;
h:=0;
end;
{comparar 1 - 2 - 3 }
if (f1=f2) and(f2=f3) and (f1<>0) then
begin
gotoxy(1,40);
if f1=2 then
write ('jogar bolinha ganhou') ;
if f1=1 then
write ('jopgador do Xiz ganhou');
f:=0;
i:=1;
end;
{comparar 4 - 5 -6 }
if (f4=f5) and (f6=f7) and (f4<>0) then
begin
gotoxy(1,40);
if f4=2 then
write ('jogar bolinha ganhou') ;
if f4=1 then
write ('jopgador do Xiz ganhou');
f:=0;
i:=1;
end;
{comparar 7 - 8 - 9 }
if (f7=f8) and(f8=f9) and (f7<>0) then
begin
gotoxy(1,40);
if f7=2 then
write ('jogar bolinha ganhou') ;
if f7=1 then
write ('jopgador do Xiz ganhou');
f:=0;
i:=1;
end;
{comparar 1 - 4 - 7 }
if (f1=f4) and(f4=f7) and (f1<>0) then
begin
gotoxy(1,40);
if f1=2 then
write ('jogar bolinha ganhou') ;
if f1=1 then
write ('jopgador do Xiz ganhou');
f:=0;
i:=1;
end;
{comparar 2 - 5 - 8 }
if (f2=f5) and(f5=f8) and (f2<>0) then
begin
gotoxy(1,40);
if f2=2 then
write ('jogar bolinha ganhou') ;
if f2=1 then
write ('jopgador do Xiz ganhou');
f:=0;
i:=1;
end;
{comparar 3 - 6 - 9 }
if (f3=f6) and(f6=f9) and (f3<>0) then
begin
gotoxy(1,40);
if f3=2 then
write ('jogar bolinha ganhou') ;
if f3=1 then
write ('jopgador do Xiz ganhou');
f:=0;
i:=1;
end;
{comparar 1 - 5 - 9 }
if (f1=f5) and(f5=f9) and (f1<>0) then
begin
gotoxy(1,40);
if f1=2 then
write ('jogar bolinha ganhou') ;
if f1=1 then
write ('jopgador do Xiz ganhou');
f:=0;
i:=1;
end;

{comparar 3 - 5 - 7 }
if (f3=f5) and(f5=f7) and (f3<>0) then
begin
gotoxy(1,40);
if f3=2 then
write ('jogar bolinha ganhou') ;
if f3=1 then
write ('jopgador do Xiz ganhou');
f:=0;
i:=1;
end;
{Comparar para dar velha}
if (f1<>0) and (f2<>0) and (f3<>0) and
(f4<>0) and (f5<>0) and (f6<>0) and
(f7<>0) and (f8<>0) and (f9<>0) then
begin
gotoxy(1,40);
write ('velha ganhou');
f:=0
end;
until f=0;
readkey;
end.

Link para o comentário
Compartilhar em outros sites

program jvelha;

uses crt;

var a,b,d,e,f,g,h,i,x1,x2,f1,f2,f3,f4,f5,f6,f7,f8,f9,y1,y2:integer;

Olá!

Acho que ficaria mais simples se você utilizasse uma matriz 3x3 para guardar os valores das jogadas, que seriam 'X' e 'O'.

Já comecei a trabalhar no jogo...

Estou usando função e procedimento também...

Ainda não está pronto, é só o início...

Aí vai o código

program jvelha;
uses crt;

type
tabuleiro = array [1..3, 1..3] of char;

var
jogador1, jogador2: string;
tab: tabuleiro;

//==============================================================================
procedure InicializarTabuleiro;
var
i, j: integer;
begin
for i:= 1 to 3 do
for j:= 1 to 3 do
tab[i,j]:=' ';
end;

//==============================================================================
function ExisteVencedor: boolean;
var
i: integer;
begin
ExisteVencedor:= false;
i:=1;
//Verifica as horizontais e verticais
while(i<=3) and not ExisteVencedor do begin
if(tab[i,1]=tab[i,2]) then begin //Horizontais
if(tab[i,2]=tab[i,3]) then
ExisteVencedor:= true;
end else
if(tab[1,i]=tab[2,i]) then //Verticais
if(tab[2,i]=tab[3,i]) then
ExisteVencedor:= true;
i:=i+1;
end;

//Caso não haja vencedor nas horizontais ou nas verticais, verifica na diagonal.
if(not ExisteVencedor) then
if(tab[1,1]=tab[2,2]) then begin
if(tab[2,2]=tab[3,3])then
ExisteVencedor:=true;
end else
if(tab[1,3]=tab[2,2]) then
if(tab[2,2]=tab[3,2]) then
ExisteVencedor:= true;

end;

//==============================================================================
//==================================Principal===================================
//==============================================================================
BEGIN
clrscr;
write (' JOGO DA VELHA');
writeln;
writeln(' 1§ jogador: '); readln(jogador1);
writeln(' 2§ jogador: '); readln(jogador2);

readkey; END.

Link para o comentário
Compartilhar em outros sites

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...