Ir para conteúdo

POWERED BY:

Arquivado

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

Roberto Silva Santos

Jogo da Velha

Recommended Posts

Caroa amigo infalivel

este codigo do jogo da velha foi postado em junho do ano passado por Angel

e como eu e o amigo Gustavo esta tentando ver este codigo compilando 100% resolvi reemposta-lo

 

Ele esta rodando mas qd chega no final que a um vencedor onde ele deveria perguntar se deseja continuar ele ate volta no a matriz, eu ate acrescentei um "inicio:" , "goto inicio;" para ele voltar mas qd volta, volta com as opção ja celecionadas e na sequencia da erro.

Veja o codigo

 

 

CODE
#include <stdio.h>

#include <stdlib.h>

#include <conio.h>

 

main(void)

{

inicio:

char m[3][3]={'1','2','3','4','5','6','7','8','9'};

int vaux[8];

int col, lin, i, j,cont, jogadavalida, posicao,jogador,temvencedor,aux;

char novajogada='n';

 

temvencedor=0;

jogador=0;

cont=0;

aux=1;

 

jogadavalida=0;

printf("===JOGO DA VELHA===");

printf("\n");

system ("color 3F");

while ((jogadavalida < 9) && (temvencedor==0))

 

{

//imprime a matriz do jogo

 

printf("\n");

printf("Jogador 1 -> x\n");

printf("Jogador 2 -> 0\n");

for (col=0; col < 3; col++)

{

printf("\n");

for (lin=0; lin < 3; lin++)

printf("%c|", m[col][lin]);

}

printf("\n");

printf("\n");

// mod para verificar qual jogador deve jogar

if (jogadavalida % 2 ==0)

{

printf("jogador 1 escolha a posicao:");

scanf ("%d",&posicao);

jogador=1;

printf("\n");

}

else

{

printf("\n");

printf("jogador 2 escolha a posicao:");

scanf("%d",&posicao);

jogador=2;

printf("\n");

}

//le a posicao ateh que seja digitada uma posicao valida

while ((posicao <1) ||(posicao >9 ))

{

printf("posicao invalida, digite numeros de 1 a 9 :");

scanf("%d",&posicao);

}

// o if verifica se a posicao ja foi digitada

// verificando posicao na matriz e atribuindo valores x ou o

cont=cont+1;

switch (posicao)

{

case 1:

 

if((m[0][0]!='x')&&(m[0][0]!='o'))

{

if (jogador == 1)

{

m[0][0]='x';

}

else

{

m[0][0]='o';

}

}

else

{

printf("posicao jah utilizada, para continuar e digitar outra posicao\n");

printf("digite 0\n");

scanf("%d",&aux);

jogadavalida=jogadavalida-1;

}

break;

case 2:

if((m[0][1]!='x')&&(m[0][1]!='o'))

{

if (jogador==1)

{

m[0][1]='x';

}

else

{

m[0][1]='o';

}

}

else

{

printf("posicao jah utilizada, para continuar e digitar outra posicao\n");

printf("digite 0\n");

scanf("%d",&aux);

jogadavalida=jogadavalida-1;

}

 

break;

case 3:

if((m[0][2]!='x')&&(m[0][2]!='o'))

{

if (jogador==1)

{

m[0][2]='x';

}

else

{

m[0][2]='o';

}

}

else

{

printf("posicao jah utilizada, para continuar e digitar outra posicao\n");

printf("digite 0\n");

scanf("%d",&aux);

jogadavalida=jogadavalida-1;

}

break;

case 4:

if((m[1][0]!='x')&&(m[1][0]!='o'))

{

if (jogador ==1)

{

m[1][0]='x';

}

else

{

m[1][0]='o';

}

}

else

{

printf("posicao jah utilizada, para continuar e digitar outra posicao\n");

printf("digite 0\n");

scanf("%d",&aux);

jogadavalida=jogadavalida-1;

}

break;

case 5:

if((m[1][1]!='x')&&(m[1][1]!='o'))

{

if (jogador==1)

{

m[1][1]='x';

}

else

{

m[1][1]='o';

}

}

else

{

printf("posicao jah utilizada, para continuar e digitar outra posicao\n");

printf("digite 0\n");

scanf("%d",&aux);

jogadavalida=jogadavalida-1;

}

break;

case 6:

if((m[1][2]!='x')&&(m[1][2]!='o'))

{

if (jogador==1)

{

m[1][2]='x';

}

else

{

m[1][2]='o';

}

}

else

{

printf("posicao jah utilizada, para continuar e digitar outra posicao\n");

printf("digite 0\n");

scanf("%d",&aux);

jogadavalida=jogadavalida-1;

}

break;

case 7:

if((m[2][0]!='x')&&(m[2][0]!='o'))

{

if (jogador==1)

{

m[2][0]='x';

}

else

{

m[2][0]='o';

}

}

else

{

printf("posicao jah utilizada, para continuar e digitar outra posicao\n");

printf("digite 0\n");

scanf("%d",&aux);

jogadavalida=jogadavalida-1;

}

break;

case 8:

if((m[2][1]!='x')&&(m[2][1]!='o'))

{

if (jogador==1)

{

m[2][1]='x';

}

else

{

m[2][1]='o';

}

}

else

{

printf("posicao jah utilizada, para continuar e digitar outra posicao\n");

printf("digite 0\n");

scanf("%d",&aux);

jogadavalida=jogadavalida-1;

}

break;

case 9:

if((m[2][2]!='x')&&(m[2][2]!='o'))

{

if (jogador==1)

{

m[2][2]='x';

}

else

{

m[2][2]='o';

}

}

else

{

printf("posicao jah utilizada, para continuar e digitar outra posicao\n");

printf("digite 0\n");

scanf("%d",&aux);

jogadavalida=jogadavalida-1;

}

break;

}

// verificacao de quem ganhou considerando que a partir da 5 jogada

// pode haver vencedor

if (cont > 4)

{

// switch (vencedor)

// comparando linha 0 e colunas

if ((m[0][0]== m[0][1]) && (m[0][0]== m[0][2]))

{

temvencedor=1;

if (m[0][0] == 'x')

{

printf("OK!!! Jogador 1 eh o vencedor O_o\n");

}

else

{

printf("OK!!! Jogador 2 eh o vencedor O_o\n");

}

}

// comparando linha 1 e colunas

 

if ((m[1][0]== m[1][1]) && (m[1][0]== m[1][2]))

{

temvencedor=1;

if (m[1][0]=='x')

{

printf("OK!!! Jogador 1 eh o vencedor O_o\n");

}

else

{

printf("OK!!! Jogador 2 eh o vencedor O_o\n");

}

}

//comparando linha 2 e colunas

if ((m[2][0]== m[2][1]) && (m[2][0]== m[2][2]))

{

temvencedor=1;

if (m[2][0]=='x')

{

printf("OK!!! Jogador 1 eh o vencedor O_o\n");

}

else

{

printf("OK !!! Jogador 2 eh o vencedor O_o\n");

}

}

//comparando coluna 0

if ((m[0][0]== m[1][0]) && (m[0][0]==m[2][0]))

{

temvencedor=1;

if (m[0][0]=='x')

{

printf("OK!!! Jogador 1 eh o vencedor O_O\n");

}

else

{

printf("OK!!! Jogador 2 eh o vencedor O_o\n");

}

}

// comparando coluna 1

if ((m[0][1]==m[1][1]) && (m[0][1]==m[2][1]))

{

temvencedor=1;

if (m[0][1]=='x')

{

printf("OK!!! Jogador 1 eh o vencedor O_o\n");

}

else

{

printf("OK!!! Jogador 2 eh o vencedor O_o\n");

}

}

 

//comparando coluna 2

if ((m[0][2]==m[1][2]) && (m[0][2]==m[2][2]))

{

temvencedor=1;

if (m[0][2]=='x')

{

printf("OK!!! Jogador 1 eh o vencedor O_o\n");

}

else

{

printf ("OK!!! Jogador 2 eh o vencedor O_o\n");

}

}

/* comparando diagonal '\' */

if ((m[0][0]==m[1][1]) && (m[0][0]== m[2][2]))

{

temvencedor=1;

if (m[0][0]=='x')

{

printf("OK!!! Jogador 1 eh o vencedor O_o\n");

}

else

{

printf("OK!!! Jogador 2 eh o vencedor O_o\n");

}

}

/* comparando diagonal '/' */

 

if ((m[0][2]==m[1][1]) && (m[0][2]==m[2][0]))

{

temvencedor=1;

if (m[0][2]=='x')

{

printf("OK!!! Jogador 1 eh o vencedor O_o\n");

}

else

{

printf("OK!!! Jogador 2 eh o vencedor O_o\n");

}

}

if ((cont==9) && (temvencedor==0))

{

printf("Nao ah vencedor\n");

}

//fim comapracoes para verificacao de vencedor

 

 

 

}//fim if cont

if (temvencedor==1)

{

getchar ();

printf("deseja jogar novamente?");

scanf("%c",&novajogada);

printf("\n");

while ((novajogada == 'n')&&(temvencedor==1));

{

//scanf("%c",&novajogada); aki ele ñ esta dando certo

printf("\n");

}

 

if (novajogada=='s')

 

{

temvencedor=0;

jogadavalida=0;

novajogada='n';

m[3][3]='1','2','3','4','5','6','7','8','9';

}

else

{

printf("FIM DO JOGO!!!");

}

}

 

 

 

 

jogadavalida = jogadavalida+1;

 

}

goto inicio;

 

}

Compartilhar este post


Link para o post
Compartilhar em outros sites

Acho que deve tá dando problema de tá declarando as variáveis denovo!

Põe o label inicio depois da declaração das variáveis e define os valores delas não na declaração mas depois do inicio:.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Sei que não tem muito a ver, mas a quase um ano fiz um jogo da velha, bem legal por sinal, caso queira testa-lo, espero que ainda funcione, rsrs.

 

Abraço. A única jogada que consegui para ganhar foi essa 3 1 - 2 3 - 3 3 - 1 3.

 

#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<windows.h>
#include<time.h>

char M[4][4],op; // Variaveis globais
int L,C,controle=0,pmaquina=0,pusuario=0,pempate=0;

// Função de abertura, margem e função sleep para dar um tempo a cada printf
void abertura (){printf("\n\n\n");printf("		\xC9\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xBB\n");printf("		\xBA \t												\t\xBA \n");Sleep(100);printf("		\xBA \t	   JJJJJ   OOOOOOO   GGGGGGG   OOOOOOO			  \xBA \n");Sleep(100);printf("		\xBA \t		  JJ   OOOOOOO   GGGGGGG   OOOOOOO			  \xBA \n");Sleep(100);printf("		\xBA \t		  JJ   OO   OO   GG		OO   OO			  \xBA \n");Sleep(10);printf("		\xBA \t		  JJ   OO   OO   GG GGGG   OO   OO			  \xBA \n");Sleep(100);printf("		\xBA \t		  JJ   OO   OO   GG   GG   OO   OO			  \xBA \n");Sleep(100);printf("		\xBA \t	 JJJJJJJ   OOOOOOO   GGGGGGG   OOOOOOO			  \xBA \n");Sleep(10);printf("		\xBA \t	 JJJJJJ	OOOOOOO   GGGGGGG   OOOOOOO			  \xBA \n");Sleep(100);printf("		\xBA \t														\xBA \n");Sleep(100);printf("		\xBA \t														\xBA \n");Sleep(100);printf("		\xBA \t														\xBA \n");Sleep(100);printf("		\xBA \t				DDDDD		AA						 \xBA \n");Sleep(100);printf("		\xBA \t				DDDDDD	 AAAAAA					   \xBA \n");Sleep(100);printf("		\xBA \t				DD   DD   AA	AA					  \xBA \n");Sleep(10);printf("		\xBA \t				DD   DD   AA	AA					  \xBA \n");Sleep(100);printf("		\xBA \t				DD   DD   AAAAAAAA					  \xBA \n");Sleep(100);printf("		\xBA \t				DDDDDD	AAAAAAAA					  \xBA \n");Sleep(10);printf("		\xBA \t				DDDDD	 AA	AA					  \xBA \n");Sleep(100);printf("		\xBA \t														\xBA \n");Sleep(100);printf("		\xBA \t														\xBA \n");Sleep(100);printf("		\xBA \t														\xBA \n");Sleep(100);printf("		\xBA	  VV   VV   EEEEEEE	LL		HH   HH	  AA		   \xBA \n");Sleep(100);printf("		\xBA	  VV   VV   EEEEEEE	LL		HH   HH	AAAAAA		 \xBA \n");Sleep(100);printf("		\xBA	  VV   VV   EE		 LL		HH   HH   AA	AA		\xBA \n");Sleep(10);printf("		\xBA	  VV   VV   EEEEEEE	LL		HHHHHHH   AA	AA		\xBA \n");Sleep(100);printf("		\xBA	   VV VV	EE		 LL		HH   HH   AAAAAAAA		\xBA \n");Sleep(100);printf("		\xBA		VVV	 EEEEEEE	LLLLLLL   HH   HH   AAAAAAAA		\xBA \n");Sleep(10);printf("		\xBA		 V	  EEEEEEE	LLLLLLL   HH   HH   AA	AA		\xBA \n");Sleep(100);printf("		\xBA															   \xBA \n");Sleep(100);printf("		\xC8\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xBC\n");Sleep(1000);}

// Função de loading, usa os recursos de margem e a sleep como a função de abertura; o system seve para limpar a tela 
void loading(){system("cls");printf("\n\n\n");printf("		\xC9\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xBB\n");printf("		\xBA							LOADING							 \xBA \n");printf("		\xC8\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xBC\n");printf("\n		___");Sleep(100);printf("___");Sleep(100);printf("___");Sleep(10);printf("___");Sleep(100);printf("__");Sleep(100);printf("__");Sleep(10);printf("___");Sleep(100);printf("___");Sleep(100);printf("___");Sleep(10);printf("___");Sleep(100);printf("__");Sleep(100);printf("__");Sleep(10);printf("___");Sleep(10);printf("___");Sleep(100);printf("__");Sleep(100);printf("__");Sleep(10);printf("___");Sleep(10);printf("___");Sleep(100);printf("__");Sleep(100);printf("__");Sleep(10);printf("___");Sleep(10);printf("___");Sleep(100);printf("__");Sleep(100);printf("__");Sleep(10);printf("__");Sleep(100);printf("__");Sleep(10);}


void menu()
	 {
	 system("cls"); // Limpa a tela
	 controle=0;
	 printf("\xC9\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xBB");
	 printf("\n\xBA   \t	 \t															  \xBA");
	 printf("\n\xBA							..: JOGO DA VELHA :..							\xBA");
	 printf("\n\xBA   \t	 \t															  \xBA");
	 printf("\n\xBA\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xBA");
	 printf("\n\xBA   \t							 MENU:									\xBA");
	 printf("\n\xBA\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xBA");
	 printf("\n\xBA   \t\xBA \t															  \xBA");
	 printf("\n\xBA 1 \t\xBA \tJOGAR														 \xBA");
	 printf("\n\xBA   \t\xBA \t															  \xBA");
	 printf("\n\xBA\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xBA");
	 printf("\n\xBA   \t\xBA \t															  \xBA");
	 printf("\n\xBA 2 \t\xBA \tINSTRUCOES													\xBA");
	 printf("\n\xBA   \t\xBA \t															  \xBA");
	 printf("\n\xBA\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xBA");
	 printf("\n\xBA   \t\xBA \t															  \xBA");
	 printf("\n\xBA 3 \t\xBA \tCREDITOS													  \xBA");
	 printf("\n\xBA   \t\xBA \t															  \xBA");
	 printf("\n\xBA\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xBA");
	 printf("\n\xBA   \t\xBA \t															  \xBA");
	 printf("\n\xBA 4 \t\xBA \tSAIR														  \xBA");
	 printf("\n\xBA   \t\xBA \t															  \xBA");
	 printf("\n\xC8\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xBC\n\n");//opções do menu
	 scanf("%d",&op); // Leitura da opção do menu.
	 }

void iniciar () // Funçao para inicializar todas as possibilidades de escolha com espaço.
	 {
	 for(L=0;L<4;L++) // Passar por todas as linhas
		  {
		  for(C=0;C<4;C++) // Passar por todas as colunas
			   {
			   M[L][C]=' ';
			   }
		  }
	 system("cls");// Limpa a tela.
	 // A seguir a matriz é mostrada em forma do jogo da velha.
	 printf("..: Jogo da Velha :..\n\n");printf("\xC9\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xBB\n");printf("\xBA PLACAR:		   \xBA\n\xBA Usuario - %d	   \xBA\n\xBA Maquina - %d	   \xBA\n\xBA Empates - %d	   \xBA",pusuario,pmaquina,pempate);printf("\n\xC8\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xBC\n");printf("\n\t\t\t\t	 |   |   ");printf("\n\t\t\t\t   %c | %c | %c  ",M[1][1],M[1][2],M[1][3]);printf("\n\t\t\t\t_____|___|_____");printf("\n\t\t\t\t	 |   |   ");printf("\n\t\t\t\t   %c | %c | %c  ",M[2][1],M[2][2],M[2][3]);printf("\n\t\t\t\t_____|___|_____");printf("\n\t\t\t\t	 |   |   ");printf("\n\t\t\t\t   %c | %c | %c ",M[3][1],M[3][2],M[3][3]);printf("\n\t\t\t\t	 |   |  ");
	 }

void jogador() //Vez do jogador.
	 {
	 int teste=0,testelinha=0,testecoluna=0,LT,CT;
	 controle=0;
	 while(teste==0)
		  {
		  while(testelinha==0)
			   {
			   printf("\nInforme a linha: ");scanf("%d",&LT);// Lê a linha.
			   if ((LT>=1)&&(LT<=3)) // Testa se o valor digitado é válido.
					{
					L=LT;
					testelinha=1;
					}
					else printf("Digite valor da linha maior que 1 e menor que 3. \n");
			   }
		  while(testecoluna==0)
			   {
			   printf("Informe a coluna: ");scanf("%d",&CT);// Lê a coluna.
			   if ((CT>=1)&&(CT<=3)) // Testa se o valor digitado é valido.
					{
					C=CT;
					testecoluna=1;
					}
					else printf("Digite valor da coluna maior que 1 e menor que 3. \n\n");
			   }
		  if (M[L][C]==' ') // Testa se a posição escolhida está vazia.
			   {
			   M[L][C]='X'; // A posição escolhida recebe um 'X'.
			   teste=1;
			   }
			   else {
					printf("\nPosicao invalida, tente novamente.\n");
					testelinha=0;
					testecoluna=0;
					}
		  }
	 system("cls"); // Limpa a tela.
	 printf("..: Jogo da Velha :..\n\n");printf("\xC9\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xBB\n");printf("\xBA PLACAR:		   \xBA\n\xBA Usuario - %d	   \xBA\n\xBA Maquina - %d	   \xBA\n\xBA Empates - %d	   \xBA",pusuario,pmaquina,pempate);printf("\n\xC8\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xBC\n");
   
	 // A seguir é mostrada a matriz com a opção inclusa.
	 printf("\n\t\t\t\t	 |   |   ");printf("\n\t\t\t\t   %c | %c | %c  ",M[1][1],M[1][2],M[1][3]);printf("\n\t\t\t\t_____|___|_____");printf("\n\t\t\t\t	 |   |   ");printf("\n\t\t\t\t   %c | %c | %c  ",M[2][1],M[2][2],M[2][3]);printf("\n\t\t\t\t_____|___|_____");printf("\n\t\t\t\t	 |   |   ");printf("\n\t\t\t\t   %c | %c | %c ",M[3][1],M[3][2],M[3][3]);printf("\n\t\t\t\t	 |   |  ");

	 }   

int trava() /* "Cérebro" da máquina. Funciona de modo a procurar a melhor jogada, com ordem de prioridade. Primeiramente testa se há possibilidade de vencer e joga, caso não, testa se há
			   possiblidade do usuário vencer, caso não tambem, escolhe uma posição mais adequada ao lance. */
	  {
	  // Testa as possibilidades de vencer nas linhas.
	  if ((M[1][1]=='O')&&(M[1][2]=='O')&&(M[1][3]==' ')&&(M[1][3]!='X')){M[1][3]='O';}else
	  if ((M[1][1]=='O')&&(M[1][3]=='O')&&(M[1][2]==' ')&&(M[1][2]!='X')){M[1][2]='O';}else
	  if ((M[1][2]=='O')&&(M[1][3]=='O')&&(M[1][1]==' ')&&(M[1][1]!='X')){M[1][3]='O';}else
	
	  if ((M[2][1]=='O')&&(M[2][2]=='O')&&(M[2][3]==' ')&&(M[2][3]!='X')){M[2][3]='O';}else
	  if ((M[2][2]=='O')&&(M[2][3]=='O')&&(M[2][1]==' ')&&(M[2][1]!='X')){M[1][3]='O';}else
	  if ((M[2][1]=='O')&&(M[2][3]=='O')&&(M[2][2]==' ')&&(M[2][2]!='X')){M[1][3]='O';}else
	
	  if ((M[3][1]=='O')&&(M[3][2]=='O')&&(M[3][3]==' ')&&(M[3][3]!='X')){M[3][3]='O';}else
	  if ((M[3][2]=='O')&&(M[3][3]=='O')&&(M[3][1]==' ')&&(M[3][1]!='X')){M[3][1]='O';}else
	  if ((M[3][1]=='O')&&(M[3][3]=='O')&&(M[3][2]==' ')&&(M[3][2]!='X')){M[3][2]='O';}else
	  
	  // Testa as possibilidades de vencer nas diagonais.
	  if ((M[1][1]=='O')&&(M[2][2]=='O')&&(M[3][3]==' ')&&(M[3][3]!='X')){M[3][3]='O';}else
	  if ((M[1][1]=='O')&&(M[3][3]=='O')&&(M[2][2]==' ')&&(M[2][2]!='X')){M[2][2]='O';}else
	  if ((M[2][2]=='O')&&(M[3][3]=='O')&&(M[1][1]==' ')&&(M[1][1]!='X')){M[1][1]='O';}else
	
	  if ((M[1][3]=='O')&&(M[2][2]=='O')&&(M[3][1]==' ')&&(M[3][1]!='X')){M[3][1]='O';}else
	  if ((M[2][2]=='O')&&(M[3][1]=='O')&&(M[1][3]==' ')&&(M[1][3]!='X')){M[1][3]='O';}else
	  if ((M[1][3]=='O')&&(M[3][1]=='O')&&(M[2][2]==' ')&&(M[2][2]!='X')){M[2][2]='O';}else
	  
	  // Testa as possibilidades de vencer nas colunas.
	  if ((M[1][1]=='O')&&(M[2][1]=='O')&&(M[3][1]==' ')&&(M[3][1]!='X')){M[3][1]='O';}else
	  if ((M[1][1]=='O')&&(M[3][1]=='O')&&(M[2][1]==' ')&&(M[2][1]!='X')){M[2][1]='O';}else
	  if ((M[2][1]=='O')&&(M[3][1]=='O')&&(M[1][1]==' ')&&(M[1][1]!='X')){M[1][1]='O';}else
	  
	  if ((M[1][2]=='O')&&(M[2][2]=='O')&&(M[3][2]==' ')&&(M[3][2]!='X')){M[3][2]='O';}else
	  if ((M[1][2]=='O')&&(M[3][2]=='O')&&(M[2][2]==' ')&&(M[2][2]!='X')){M[2][2]='O';}else
	  if ((M[2][2]=='O')&&(M[3][2]=='O')&&(M[1][2]==' ')&&(M[1][2]!='X')){M[1][2]='O';}else
	  
	  if ((M[1][3]=='O')&&(M[2][3]=='O')&&(M[3][3]==' ')&&(M[3][3]!='X')){M[3][3]='O';}else
	  if ((M[1][3]=='O')&&(M[3][3]=='O')&&(M[2][3]==' ')&&(M[2][3]!='X')){M[2][3]='O';}else
	  if ((M[2][3]=='O')&&(M[3][3]=='O')&&(M[1][3]==' ')&&(M[1][3]!='X')){M[1][3]='O';}else
	  
	  // Testa as possibilidades de o usuário vencer nas linhas.
	  if ((M[1][1]=='X')&&(M[1][2]=='X')&&(M[1][3]==' ')&&(M[1][3]!='O')){M[1][3]='O';}else
	  if ((M[2][1]=='X')&&(M[2][2]=='X')&&(M[2][3]==' ')&&(M[2][3]!='O')){M[2][3]='O';}else
	  if ((M[3][1]=='X')&&(M[3][2]=='X')&&(M[3][3]==' ')&&(M[3][3]!='O')){M[3][3]='O';}else
	
	  if ((M[1][1]=='X')&&(M[1][3]=='X')&&(M[1][2]==' ')&&(M[1][2]!='O')){M[1][2]='O';}else
	  if ((M[2][1]=='X')&&(M[2][3]=='X')&&(M[2][2]==' ')&&(M[2][2]!='O')){M[2][2]='O';}else
	  if ((M[3][1]=='X')&&(M[3][3]=='X')&&(M[3][2]==' ')&&(M[3][2]!='O')){M[3][2]='O';}else
	
	  if ((M[1][2]=='X')&&(M[1][3]=='X')&&(M[1][1]==' ')&&(M[1][1]!='O')){M[1][1]='O';}else
	  if ((M[2][2]=='X')&&(M[2][3]=='X')&&(M[2][1]==' ')&&(M[2][1]!='O')){M[2][1]='O';}else
	  if ((M[3][2]=='X')&&(M[3][3]=='X')&&(M[3][1]==' ')&&(M[3][1]!='O')){M[3][1]='O';}else
	
	  // Testa as possibilidades de o usuário vencer nas colunas.
	  if ((M[1][1]=='X')&&(M[2][1]=='X')&&(M[3][1]==' ')&&(M[3][1]!='O')){M[3][1]='O';}else
	  if ((M[1][2]=='X')&&(M[2][2]=='X')&&(M[3][2]==' ')&&(M[3][2]!='O')){M[3][2]='O';}else
	  if ((M[1][3]=='X')&&(M[2][3]=='X')&&(M[3][3]==' ')&&(M[3][3]!='O')){M[3][3]='O';}else
	  
	  if ((M[1][1]=='X')&&(M[3][1]=='X')&&(M[3][2]==' ')&&(M[2][1]!='O')){M[2][1]='O';}else
	  if ((M[1][2]=='X')&&(M[3][2]=='X')&&(M[2][2]==' ')&&(M[2][2]!='O')){M[2][2]='O';}else
	  if ((M[1][3]=='X')&&(M[3][3]=='X')&&(M[2][3]==' ')&&(M[2][3]!='O')){M[2][3]='O';}else
	  
	  if ((M[2][1]=='X')&&(M[3][1]=='X')&&(M[1][1]==' ')&&(M[1][1]!='O')){M[1][1]='O';}else
	  if ((M[2][2]=='X')&&(M[3][2]=='X')&&(M[1][2]==' ')&&(M[1][2]!='O')){M[1][2]='O';}else
	  if ((M[2][3]=='X')&&(M[3][3]=='X')&&(M[1][3]==' ')&&(M[1][3]!='O')){M[1][3]='O';}else

	  // Testa as possibilidades de o usuário vencer nas diagonais.	   
	  if ((M[1][1]=='X')&&(M[2][2]=='X')&&(M[3][3]==' ')&&(M[3][3]!='O')){M[3][3]='O';}else
	  if ((M[3][3]=='X')&&(M[2][2]=='X')&&(M[1][1]=='O')&&(M[3][1]==' ')){M[3][1]='O';}else 
	  if ((M[3][3]=='X')&&(M[2][2]=='X')&&(M[1][1]==' ')&&(M[1][1]!='O')){M[1][1]='O';}else
	  if ((M[1][1]=='X')&&(M[3][3]=='X')&&(M[2][2]==' ')&&(M[2][2]!='O')){M[2][2]='O';}else
	  
	  if ((M[3][1]=='X')&&(M[2][2]=='X')&&(M[1][3]==' ')&&(M[1][3]!='O')){M[1][3]='O';}else
	  if ((M[2][2]=='X')&&(M[1][3]=='X')&&(M[3][1]==' ')&&(M[3][1]!='O')){M[3][1]='O';}else
	  if ((M[1][3]=='X')&&(M[3][1]=='X')&&(M[2][2]==' ')&&(M[2][2]!='O')){M[2][2]='O';}else
	  
	  // Jogadas a não deixar o usuário vencer.
	  if ((M[2][2]=='X')&&(M[1][1]==' ')){M[1][1]='O';}else
	  if ((M[2][3]=='X')&&(M[3][2]=='X')&&(M[3][3]==' ')&&(M[2][2]=='O')){M[3][3]='O';}else
	  if ((M[1][2]=='X')&&(M[2][3]=='X')&&(M[1][3]==' ')&&(M[2][2]=='O')){M[1][3]='O';}else
	  
	  // Jogadas caso não haja possibilidade de máquina ou usuário vencer.
	  if ((M[2][2]==' ')){M[2][2]='O';}else
	  if ((M[2][1]==' ')){M[2][1]='O';}else
	  if ((M[1][1]==' ')){M[1][1]='O';}else
	  if ((M[1][3]==' ')){M[1][3]='O';}else
	  if ((M[1][2]==' ')){M[1][2]='O';}else
	  if ((M[2][3]==' ')){M[2][3]='O';}else
	  if ((M[3][1]==' ')){M[3][1]='O';}else
	  if ((M[3][2]==' ')){M[3][2]='O';}else   
	  if ((M[3][3]==' ')){M[3][3]='O';}
	  } 

void usuarioganha() // Função de quando usuário vence.
	 {
	 Sleep(1000);
	 system("cls");printf("\n\n\n");printf("		\xC9\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xBB\n");printf("		\xBA																 \xBA \n");Sleep(100);printf("		\xBA												^^^			  \xBA \n");Sleep(100);printf("		\xBA											  ^^   ^^			\xBA \n");Sleep(100);printf("		\xBA																 \xBA \n");Sleep(100);printf("		\xBA			 VV   VV	OOOOOOO	 CCCCCC	EEEEEEE			\xBA \n");Sleep(100);printf("		\xBA			 VV   VV	OOOOOOO	CCCCCCC	EEEEEEE			\xBA \n");Sleep(100);printf("		\xBA			 VV   VV	OO   OO	CC		 EE				 \xBA \n");Sleep(10);printf("		\xBA			 VV   VV	OO   OO	CC		 EEEEEEE			\xBA \n");Sleep(100);printf("		\xBA			  VV VV	 OO   OO	CC		 EE				 \xBA \n");Sleep(100);printf("		\xBA			   VVV	  OOOOOOO	CCCCCCC	EEEEEEE			\xBA \n");Sleep(10);printf("		\xBA				V	   OOOOOOO	 CCCCCC	EEEEEEE			\xBA \n");Sleep(100);printf("		\xBA																 \xBA \n");Sleep(100);printf("		\xBA																 \xBA \n");Sleep(100);printf("		\xBA																 \xBA \n");Sleep(100);printf("		\xBA   GGGGGGG	  AA	  NN	NN   HH   HH   OOOOOOO   UU   UU   \xBA \n");Sleep(100);printf("		\xBA   GGGGGGG	AAAAAA	NNN   NN   HH   HH   OOOOOOO   UU   UU   \xBA \n");Sleep(100);printf("		\xBA   GG		AA	AA   NNNN  NN   HH   HH   OO   OO   UU   UU   \xBA \n");Sleep(10);printf("		\xBA   GG GGGG   AA	AA   NN NN NN   HHHHHHH   OO   OO   UU   UU   \xBA \n");Sleep(100);printf("		\xBA   GG   GG   AAAAAAAA   NN  NNNN   HH   HH   OO   OO   UU   UU   \xBA \n");Sleep(100);printf("		\xBA   GGGGGGG   AAAAAAAA   NN   NNN   HH   HH   OOOOOOO   UUUUUUU   \xBA \n");Sleep(10);printf("		\xBA   GGGGGGG   AA	AA   NN	NN   HH   HH   OOOOOOO	UUUUU	\xBA \n");Sleep(100);printf("		\xBA																 \xBA \n");Sleep(100);printf("		\xC8\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xBC\n");Sleep(1000);
	 controle=1; // Significa o jogo acabou.
	 pusuario++;
	 getch();
	 }

void maquinaganha() // Função de quando máquina vence.
	 {
	 Sleep(1000);
	 system("cls");printf("\n\n\n");printf("		\xC9\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xBB\n");printf("		\xBA																 \xBA \n");Sleep(100);printf("		\xBA						EEEEEEE   UU   UU						\xBA \n");Sleep(100);printf("		\xBA						EEEEEEE   UU   UU						\xBA \n");Sleep(100);printf("		\xBA						EE		UU   UU						\xBA \n");Sleep(10);printf("		\xBA						EEEEEEE   UU   UU						\xBA \n");Sleep(100);printf("		\xBA						EE		UU   UU						\xBA \n");Sleep(100);printf("		\xBA						EEEEEEE   UUUUUUU						\xBA \n");Sleep(10);printf("		\xBA						EEEEEEE	UUUUU						 \xBA \n");Sleep(100);printf("		\xBA																 \xBA \n");Sleep(100);printf("		\xBA																 \xBA \n");Sleep(100);printf("		\xBA																 \xBA \n");Sleep(100);printf("		\xBA   GGGGGGG	  AA	  NN	NN   HH   HH   EEEEEEE   II   !!   \xBA \n");Sleep(100);printf("		\xBA   GGGGGGG	AAAAAA	NNN   NN   HH   HH   EEEEEEE   II   !!   \xBA \n");Sleep(100);printf("		\xBA   GG		AA	AA   NNNN  NN   HH   HH   EE		II   !!   \xBA \n");Sleep(10);printf("		\xBA   GG GGGG   AA	AA   NN NN NN   HHHHHHH   EEEEEEE   II   !!   \xBA \n");Sleep(100);printf("		\xBA   GG   GG   AAAAAAAA   NN  NNNN   HH   HH   EE		II		\xBA \n");Sleep(100);printf("		\xBA   GGGGGGG   AAAAAAAA   NN   NNN   HH   HH   EEEEEEE   II   ..   \xBA \n");Sleep(10);printf("		\xBA   GGGGGGG   AA	AA   NN	NN   HH   HH   EEEEEEE   II   ..   \xBA \n");Sleep(100);printf("		\xBA																 \xBA \n");Sleep(100);printf("		\xC8\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xBC\n");Sleep(1000);
	 controle=1; // Significa o jogo acabou.
	 pmaquina++;
	 getch();
	 }

void empate() // Função de quando tem-se um empate.
	 {
	 Sleep(1000);
	 system("cls");printf("\n\n\n");printf("		\xC9\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xBB\n");printf("		\xBA																 \xBA \n");Sleep(100);printf("		\xBA  EEEEEEE   MM	 MM   PPPPPP	   AA	 TTTTTTTT   EEEEEEE   \xBA \n");Sleep(100);printf("		\xBA  EEEEEEE   MMM   MMM   PPPPPPP	AAAAAA   TTTTTTTT   EEEEEEE   \xBA \n");Sleep(100);printf("		\xBA  EE		MMMM MMMM   PP	P   AA	AA	 TT	  EE		\xBA \n");Sleep(10);printf("		\xBA  EEEEEEE   MM  M  MM   PPPPPPP   AA	AA	 TT	  EEEEEEE   \xBA \n");Sleep(100);printf("		\xBA  EE		MM	 MM   PPPPPP	AAAAAAAA	 TT	  EE		\xBA \n");Sleep(100);printf("		\xBA  EEEEEEE   MM	 MM   PP		AAAAAAAA	 TT	  EEEEEEE   \xBA \n");Sleep(10);printf("		\xBA  EEEEEEE   MM	 MM   PP		AA	AA	 TT	  EEEEEEE   \xBA \n");Sleep(100);printf("		\xBA																 \xBA \n");Sleep(100);printf("		\xC8\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xBC\n");Sleep(1000);
	 controle=1; // Significa o jogo acabou.
	 pempate++;
	 getch();
	 }
	 
int resultado() /* Função para verificar se há um vencedor da partida. Caso seja a maquina, chama a função maquinaganha, caso seja o usuário chama a função usuarioganha.
				   Testa todas as possibilidades de linhas, colunas e diagonais. */
	 {
	 if ((M[1][1]=='O')&&(M[1][2]=='O')&&(M[1][3]=='O'))maquinaganha();else
	 if ((M[2][1]=='O')&&(M[2][2]=='O')&&(M[2][3]=='O'))maquinaganha();else
	 if ((M[3][1]=='O')&&(M[3][2]=='O')&&(M[3][3]=='O'))maquinaganha();else

	 if ((M[1][1]=='O')&&(M[1][3]=='O')&&(M[1][2]=='O'))maquinaganha();else
	 if ((M[2][1]=='O')&&(M[2][3]=='O')&&(M[2][2]=='O'))maquinaganha();else
	 if ((M[3][1]=='O')&&(M[3][3]=='O')&&(M[3][2]=='O'))maquinaganha();else
 
	 if ((M[1][2]=='O')&&(M[1][3]=='O')&&(M[1][1]=='O'))maquinaganha();else
	 if ((M[2][2]=='O')&&(M[2][3]=='O')&&(M[2][1]=='O'))maquinaganha();else
	 if ((M[3][2]=='O')&&(M[3][3]=='O')&&(M[3][1]=='O'))maquinaganha();else

	 if ((M[1][1]=='O')&&(M[2][1]=='O')&&(M[3][1]=='O'))maquinaganha();else 
	 if ((M[1][2]=='O')&&(M[2][2]=='O')&&(M[3][2]=='O'))maquinaganha();else
	 if ((M[1][3]=='O')&&(M[2][3]=='O')&&(M[3][3]=='O'))maquinaganha();else

	 if ((M[1][1]=='O')&&(M[3][1]=='O')&&(M[2][1]=='O'))maquinaganha();else
	 if ((M[1][2]=='O')&&(M[3][2]=='O')&&(M[2][2]=='O'))maquinaganha();else
	 if ((M[1][3]=='O')&&(M[3][3]=='O')&&(M[2][3]=='O'))maquinaganha();else

	 if ((M[2][1]=='O')&&(M[3][1]=='O')&&(M[1][1]=='O'))maquinaganha();else
	 if ((M[2][2]=='O')&&(M[3][2]=='O')&&(M[1][2]=='O'))maquinaganha();else
	 if ((M[2][3]=='O')&&(M[3][3]=='O')&&(M[1][3]=='O'))maquinaganha();else  

	 if ((M[1][1]=='O')&&(M[2][2]=='O')&&(M[3][3]=='O'))maquinaganha();else
	 if ((M[3][3]=='O')&&(M[2][2]=='O')&&(M[1][1]=='O'))maquinaganha();else
	 if ((M[1][1]=='O')&&(M[3][3]=='O')&&(M[2][2]=='O'))maquinaganha();else
 
	 if ((M[3][1]=='O')&&(M[2][2]=='O')&&(M[1][3]=='O'))maquinaganha();else
	 if ((M[2][2]=='O')&&(M[1][3]=='O')&&(M[3][1]=='O'))maquinaganha();else
	 if ((M[1][3]=='O')&&(M[3][1]=='O')&&(M[2][2]=='O'))maquinaganha();else	
		
	 if ((M[1][1]=='X')&&(M[1][2]=='X')&&(M[1][3]=='X'))usuarioganha();else
	 if ((M[2][1]=='X')&&(M[2][2]=='X')&&(M[2][3]=='X'))usuarioganha();else
	 if ((M[3][1]=='X')&&(M[3][2]=='X')&&(M[3][3]=='X'))usuarioganha();else
 
	 if ((M[1][1]=='X')&&(M[1][3]=='X')&&(M[1][2]=='X'))usuarioganha();else
	 if ((M[2][1]=='X')&&(M[2][3]=='X')&&(M[2][2]=='X'))usuarioganha();else
	 if ((M[3][1]=='X')&&(M[3][3]=='X')&&(M[3][2]=='X'))usuarioganha();else
  
	 if ((M[1][2]=='X')&&(M[1][3]=='X')&&(M[1][1]=='X'))usuarioganha();else
	 if ((M[2][2]=='X')&&(M[2][3]=='X')&&(M[2][1]=='X'))usuarioganha();else
	 if ((M[3][2]=='X')&&(M[3][3]=='X')&&(M[3][1]=='X'))usuarioganha();else

	 if ((M[1][1]=='X')&&(M[2][1]=='X')&&(M[3][1]=='X'))usuarioganha();else 
	 if ((M[1][2]=='X')&&(M[2][2]=='X')&&(M[3][2]=='X'))usuarioganha();else
	 if ((M[1][3]=='X')&&(M[2][3]=='X')&&(M[3][3]=='X'))usuarioganha();else

	 if ((M[1][1]=='X')&&(M[3][1]=='X')&&(M[2][1]=='X'))usuarioganha();else
	 if ((M[1][2]=='X')&&(M[3][2]=='X')&&(M[2][2]=='X'))usuarioganha();else
	 if ((M[1][3]=='X')&&(M[3][3]=='X')&&(M[2][3]=='X'))usuarioganha();else
  
	 if ((M[2][1]=='X')&&(M[3][1]=='X')&&(M[1][1]=='X'))usuarioganha();else
	 if ((M[2][2]=='X')&&(M[3][2]=='X')&&(M[1][2]=='X'))usuarioganha();else
	 if ((M[2][3]=='X')&&(M[3][3]=='X')&&(M[1][3]=='X'))usuarioganha();else

	 if ((M[1][1]=='X')&&(M[2][2]=='X')&&(M[3][3]=='X'))usuarioganha();else
	 if ((M[3][3]=='X')&&(M[2][2]=='X')&&(M[1][1]=='X'))usuarioganha();else
	 if ((M[1][1]=='X')&&(M[3][3]=='X')&&(M[2][2]=='X'))usuarioganha();else
  
	 if ((M[3][1]=='X')&&(M[2][2]=='X')&&(M[1][3]=='X'))usuarioganha();else
	 if ((M[2][2]=='X')&&(M[1][3]=='X')&&(M[3][1]=='X'))usuarioganha();else
	 if ((M[1][3]=='X')&&(M[3][1]=='X')&&(M[2][2]=='X'))usuarioganha();else
	
	 if ((M[1][1]!=' ')&&(M[1][2]!=' ')&&(M[1][3]!=' ')&&(M[2][1]!=' ')&&(M[2][2]!=' ')&&(M[2][3]!=' ')&&(M[3][1]!=' ')&&(M[3][2]!=' ')&&(M[3][3]!=' '))empate();
	 }

void maquina() //Vez da máquina.
	 {
	 int i,j;
	 trava(); // Chama o "cérebro" conferindo todas as opções.
	 // A seguir é mostrada a matriz com a opção inclusa.
	 system("cls");printf("..: Jogo da Velha :..\n\n");printf("\xC9\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xBB\n");printf("\xBA PLACAR:		   \xBA\n\xBA Usuario - %d	   \xBA\n\xBA Maquina - %d	   \xBA\n\xBA Empates - %d	   \xBA",pusuario,pmaquina,pempate);printf("\n\xC8\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xBC\n");printf("\n\t\t\t\t	 |   |   ");printf("\n\t\t\t\t   %c | %c | %c  ",M[1][1],M[1][2],M[1][3]);printf("\n\t\t\t\t_____|___|_____");printf("\n\t\t\t\t	 |   |   ");printf("\n\t\t\t\t   %c | %c | %c  ",M[2][1],M[2][2],M[2][3]);printf("\n\t\t\t\t_____|___|_____");printf("\n\t\t\t\t	 |   |   ");printf("\n\t\t\t\t   %c | %c | %c ",M[3][1],M[3][2],M[3][3]);printf("\n\t\t\t\t	 |   |  ");
	 }

void instrucoes () // Intrusões básicas sobre o jogo.
	 {
	 system("cls");
	 printf("..: Jogo da Velha :..\n\nINSTRUCOES\n\n");
	 printf("O tabuleiro e uma matriz de tres linhas por tres colunas.\n\nDois jogadores escolhem uma marcacao cada, geralmente um circulo e um xis. Popularmente chama-se o jogador 'X' de 'xis' ou 'xizinho' e o jogador 'O' de 'circulo' ou 'bolinha'.\n\nOs jogadores jogam alternadamente, uma marcacao por vez, numa lacuna que esteja vazia.\n\nO objetivo e conseguir tres circulos ou tres xis em linha, quer horizontal, vertical ou diagonal, e ao mesmo tempo, quando possivel, impedir o adversario de ganhar na proxima jogada.\n\nQuando um jogador conquista o objetivo, costuma-se riscar os tres simbolos.");
	 }

void creditos () // Créditos, somente nomes.
	 {
	 system("cls");
	 printf("..: Jogo da Velha :..\n\nESTE PROGRAMA FOI DESENVOLVIDO POR:\n");Sleep(500);printf("\nEvandro");Sleep(500);printf("\nWestphalen");Sleep(500);printf("\nCarlos");Sleep(500);printf("\nGomes");Sleep(500);printf("\n\n\tDigiane");Sleep(500);printf("\n\tRibas");Sleep(500);printf("\n\tGomes");Sleep(500);printf("\n\n\t\tRodolfo");Sleep(500);printf("\n\t\tAdamshuk");Sleep(500);printf("\n\t\tSilva");Sleep(500);printf("\n\n\t\t\tRicardo ");Sleep(500);printf("\n\t\t\tIzumi");
	 }

// Programa principal.
main()
	 {
	 int partidas,i=0;
	 abertura(); // Chama a funçao de abertura.
	 loading();// Chama a funçao de loading.
	 while(op!=4)
		  {
		  menu();
		  if(op==1)
			   {
			   printf("\nQuantas partidas pretende jogar: ");
			   scanf("%d",&partidas);
			   loading();
			   while(i<partidas)
					{
					iniciar(); // Chama a funçao iniciar para zerar a matriz e dar sequência ao jogo.
					while((controle!=1))
						 {
						 if (controle==0)
							  {
							  jogador ();// Chama a funçao para a vez do jogador.
							  resultado(); // Testa o resultado.
							  }
							  if (controle==0)
								   {
								   maquina(); // Chama a funçao para a vez da máquina.
								   resultado(); // Testa o resultado.
								   }
						 }
			   controle=0; // Inicia para um novo jogo.
			   i++;
			   }
		  printf("\nFinal:\n\n");printf("\xC9\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xBB\n");printf("\xBA PLACAR:		   \xBA\n\xBA Usuario - %d	   \xBA\n\xBA Maquina - %d	   \xBA\n\xBA Empates - %d	   \xBA",pusuario,pmaquina,pempate);printf("\n\xC8\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xBC\n");
		  pempate=0;pmaquina=0;pusuario=0;i=0; // Inicia o placar para novas partidas.
		  getch();
		  }
		  if(op==2)
			  {
			  loading();
			  instrucoes ();
			  getch();
			  }
		  if(op==3)
			  {
			  loading();
			  creditos();
			  getch();
			  }
		  if(op==4)
			  {
			  exit(0);
			  }
		  }
	 }
Uia! Não consegui fazer aparecer a barra de rolagem pra ficar menor.

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.