Jogo da velha melhorado
Publicado por Samuel Macedo 13/10/2004
[ Hits: 7.983 ]
Versão melhorada do jogo da velha que eu postei ha alguns dias atrás...
#include <stdio.h>
int ctrl[3][3];
char imp[3][3];
int ctrlf(int l1,int c1,int l2,int c2,int param)
{
int cti,ctj,chp1=0,chp2=0,chv=0,cmp,ctvelha=0;
if ( param == 1 ){
--l1; --c1;
if(ctrl[l1][c1]!= 0) return 5;
ctrl[l1][c1] = 1; imp[l1][c1] = 'X';
}
else{
--l2; --c2;
if(ctrl[l2][c2]!= 0) return 5;
ctrl[l2][c2] = 2; imp[l2][c2] = 'O';
}
for(cti=0;cti<3;cti++){
for(ctj=0;ctj<3;ctj++){
if(ctrl[cti][ctj] == 1){
++chp1;
}
if(ctrl[cti][ctj] == 2){
++chp2;
}
if(ctrl[cti][ctj] == 0){
chv = 1;
}
}
if (chp1 == 3)
return 1;
if (chp2 == 3)
return 2;
chp1 = 0;
chp2 = 0;
}//checagem linha
for(cti=0;cti<3;cti++){
for(ctj=0;ctj<3;ctj++){
if(ctrl[ctj][cti] == 1){
++chp1;
}
if(ctrl[ctj][cti] == 2){
++chp2;
}
}
if (chp1 == 3)
return 1;
if (chp2 == 3)
return 2;
chp1 = 0;
chp2 = 0;
}//checagem coluna
for(cti = 0;cti<3;cti++){
if(ctrl[cti][cti] == 1){
++chp1;
}
if(ctrl[cti][cti] == 2){
++chp2;
}
}
if (chp1 == 3)
return 1;
if (chp2 == 3)
return 2;
chp1 = 0;
chp2 = 0;
// checagem diag. principal
for(cti=0;cti<3;cti++){
for(ctj=0;ctj<3;ctj++){
if(cti + ctj == 2){
if(ctrl[cti][ctj] == 1){
++chp1;
}
if(ctrl[cti][ctj] == 2){
++chp2;
}
}
}
}
if (chp1 == 3)
return 1;
if (chp2 == 3)
return 2;
chp1 = 0;
chp2 = 0;
//checagem diag. sec.
if (chv == 0){
return 3;
}
return 0;
}
impjogo()
{
int impi, impj;
system("clear");
for(impi=0;impi<3;impi++){
for(impj=0;impj<3;impj++){
printf("%c ",imp[impi][impj]);
}
printf("\n");
}
}
int central()
{
int i,j,j1l,j1c,j2l,j2c,result,param,perg;
for(i=0;i<3;i++){
for(j=0;j<3;j++){
ctrl[i][j] = 0;
imp[i][j] = '*';
}
}
do{
do{
impjogo();
if (result == 5)
puts("Posicao ja ocupada! Jogue novamente:");
printf("==Jogador 1==\n");
do{
printf("Linha: ");
scanf("%d",&j1l);
if(j1l>3||j1l<1){
puts("Nao existe essa linha!");
puts("Digita de novo, animal:");
}
}while(j1l>3||j1l<1);
do{
printf("Coluna: ");
scanf("%d",&j1c);
if(j1c>3||j1c<1){
puts("Nao existe essa coluna!");
puts("Digita de novo, animal:");
}
}while(j1c>3||j1c<1);
result = ctrlf(j1l,j1c,j2l,j2c,1);
if ( result != 0 && result != 5)
break;
}while(result==5);
do{
impjogo();
if (result == 5)
puts("Posicao ja ocupada! Jogue novamente:");
printf("==Jogador 2==\n");
do{
printf("Linha: ");
scanf("%d",&j2l);
if(j2l>3||j2l<1){
puts("Nao existe essa linha!");
puts("Digita de novo, animal:");
}
}while(j2l>3||j2l<1);
do{
printf("Coluna: ");
scanf("%d",&j2c);
if(j2c>3||j2c<1){
puts("Nao existe essa coluna!");
puts("Digita de novo, animal:");
}
}while(j2c>3||j2c<1);
result = ctrlf(j1l,j1c,j2l,j2c,2);
}while(result==5);
}while(result == 0);
impjogo();
if (result == 1){
puts("JOGADOR 1 GANHOU");
}
if (result == 2){
puts("JOGADOR 2 GANHOU");
}
if (result == 3){
puts("VELHA...");
}
puts("Jogar novamente? ( 0 - Sim / qualquer outra tecla - Nao )");
scanf("%d",&perg);
return perg;
}
main()
{
while(central()==0){
}
}
C --> Calculadora de equações de 2º grau explicada.
Papagaiando o XFCE com temas e recursos
WhatsApp com Chamadas no Linux via Waydroid
XFCE - quase um Gnome ou Plasma mas muito mais leve
LXQT - funcional para máquinas pererecas e usuários menos exigentes
Como cortar as partes de um vídeo com passagens de áudio em branco
Tiling automático no KDE Plasma
SNMP Scan no OCS Inventory só funciona com HTTPS corretamente configurado
Links importantes de usuários do vol (4)
GOG confirma suporte oficial ao sistema Linux: "o trabalho começo... (2)
Para os fãs de DOOM, um vídeo do Romero (com dublagem em pt-br disponí... (2)









