Jogo da velha
Publicado por Valter 14/10/2008
[ Hits: 10.504 ]
Um código bem simples do jogo da velha, mas para quem está iniciando em C é bem interressante.
#include<stdio.h> #include<conio.h> #define Y 3 int main(void) { unsigned char Matriz[Y][Y]; const int TRUE = 1; const char O='O', X='X'; int l,j,i; for(i=0;i<Y;i++) for(j=0;j<Y;j++) Matriz[i][j]=' '; while(TRUE) { printf("\xB0\xB0\xB0\xB0\xB0\xB0\xB0\xB0\xB0\xB0\xB0\xB0\xB0\xB0\xB0\xB0\xB0 JOGO DA VELHA" " \xB0\xB0\xB0\xB0\xB0\xB0\xB0\xB0\xB0\xB0\xB0\xB0\xB0\xB0\xB0\xB0\xB0\n\n\n\n"); for(i=0;i<Y;i++) { printf("\t\t %c \xBA %c \xBA %c\n",Matriz[i][0],Matriz[i][1],Matriz[i][2]); if(i<Y-1) { printf("\t\t ÍÍÍ\xCEÍÍÍ\xCEÍÍÍ\n"); } } if((Matriz[0][0]==O && Matriz[0][1]==O && Matriz[0][2]==O)|| (Matriz[1][0]==O && Matriz[1][1]==O && Matriz[1][2]==O)|| (Matriz[2][0]==O && Matriz[2][1]==O && Matriz[2][2]==O)|| (Matriz[0][0]==O && Matriz[1][0]==O && Matriz[2][0]==O)|| (Matriz[0][1]==O && Matriz[1][1]==O && Matriz[2][1]==O)|| (Matriz[0][2]==O && Matriz[1][2]==O && Matriz[2][2]==O)|| (Matriz[0][0]==O && Matriz[1][1]==O && Matriz[2][2]==O)|| (Matriz[0][2]==O && Matriz[1][1]==O && Matriz[2][0]==O)) { printf("\n\n\n\n\a\t\tJogador 1, VOCE VENCEU!!!"); break; } if((Matriz[0][0]==X && Matriz[0][1]==X && Matriz[0][2]==X)|| (Matriz[1][0]==X && Matriz[1][1]==X && Matriz[1][2]==X)|| (Matriz[2][0]==X && Matriz[2][1]==X && Matriz[2][2]==X)|| (Matriz[0][0]==X && Matriz[1][0]==X && Matriz[2][0]==X)|| (Matriz[0][1]==X && Matriz[1][1]==X && Matriz[2][1]==X)|| (Matriz[0][2]==X && Matriz[1][2]==X && Matriz[2][2]==X)|| (Matriz[0][0]==X && Matriz[1][1]==X && Matriz[2][2]==X)|| (Matriz[0][2]==X && Matriz[1][1]==X && Matriz[2][0]==X)) { printf("\n\n\n\n\a\t\tJogador 2, VOCE VENCEU!!!"); break; } if(l==9) { printf("PARTIDA EMPATADA"); break; } printf("\n\n\n\n\n\n\n\n\n\n\n\nINSIRA AS COORDENADAS, "); if(l%2)printf("PLAYER 2\nLINHA: "); else printf("PLAYER 1\nLINHA: "); scanf("%d",&i); printf("COLUNA: "); scanf("%d",&j); if(Matriz[i-1][j-1]==' ') { if(l%2)Matriz[i-1][j-1]=X; else Matriz[i-1][j-1]=O; l++; } } getch(); return(0); }
Escrevendo um arquivo Unicode em C#
Instalar e Configurar o Slackware Linux em 2025
Como configurar os repositórios do apt no Debian 12 em 2025
Passkeys: A Evolução da Autenticação Digital
Instalação de distro Linux em computadores, netbooks, etc, em rede com o Clonezilla
Configurando o Conky para iniciar corretamente no sistema
3 configurações básicas que podem melhorar muito a sua edição pelo editor nano
Como colorir os logs do terminal com ccze
Instalação Microsoft Edge no Linux Mint 22
Como configurar posicionamento e movimento de janelas no Lubuntu (Openbox) com atalhos de teclado
Jogando com Proton no LInux (0)
Ingress NGINX Controller CVSS base score of 9.8 (4)
Impossível corrigir problemas, você manteve (hold) pacotes quebrados. (2)