Jogo da Velha (Corrigido)
Publicado por Leandro Jochan 13/12/2005
[ Hits: 7.311 ]
Outro jogo da velha, corri alguns Bugs do jogo, mas a maquina continua burrinha, se alguem puder me ajudar.
Jogo da velha para 1 jogador,
/* Jogo da velha para um jogador, By JoChAn - jochan@terra.com.br www.jochan.cjb.net */ #include <stdio.h> #include <stdlib.h> char matrix[3][3]; /* a matriz do jogo */ char check(void); void init_matrix(void); void get_player_move(void); void get_computer_move(void); void disp_matrix(void); void main(void) { char done; printf("Este ‚ o jogo da velha.\n"); printf("Vocˆ est jogando contra o computador.\n"); done = ' '; init_matrix(); do { disp_matrix(); get_player_move(); done = check(); /* verifica se h vencedor */ if(done!=' ') break; /* vencedor! */ get_computer_move(); done = check(); /* verifica se h vencedor */ } while(done==' '); if(done=='X') printf(" Vocˆ ganhou!\n"); else printf(" Eu ganhei!!!\n"); disp_matrix(); /* mostra as posi‡oes finais */ getch(); clrscr(); } /* Inicializa a matriz */ void init_matrix(void) { int i, j; for(i=0; i<3; i++) for(j=0; j<3; j++) matrix[i][j] = ' '; } /* Obt‚m a sua jogada */ void get_player_move(void) { int x, y; printf("Entre com as coordenadas para o X:\n"); printf("Digite o n§ da linha: "); scanf("%d",&x); printf("Digite o n§ da Coluna: "); scanf("%d", &y); x--; y--; if(matrix[x][y]!=' ') { printf("Posi‡ao invalida, tente novamente. \n"); get_player_move(); } else matrix[x][y] = 'X'; } /* Obt‚m uma jogada do computador */ void get_computer_move(void) { int i, j; for(i=0; i<3; i++) { for(j=0; j<3; j++) if(matrix[i][j]==' ') break; if(matrix[i][j]==' ') break; } if(i*j==9) { printf("Empate\n"); exit(0); } else matrix[i][j] = 'O'; } /* Mostra a matriz na tela */ void disp_matrix(void) { int t; for(t=0; t<3; t++) { printf(" %c | %c | %c ", matrix[t][0], matrix[t][1], matrix[t][2]); if(t!=2) printf("\n---|---|---\n"); } printf("\n"); } /* Verifica se h um vencedor */ char check(void) { int i; for(i=0; i<3; i++) /* verifica as linhas */ if(matrix[i][0]==matrix[i][1] && matrix[i][0]==matrix[i][2]) return matrix[i][0]; for(i=0; i<3; i++) /* verifica as colunas */ if(matrix[0][i]==matrix[1][i] && matrix[0][i]==matrix[2][i]) return matrix[0][i]; /* testa as diagonais */ if(matrix[0][0]==matrix[1][1] && matrix[1][1]==matrix[2][2]) return matrix[0][0]; if(matrix[0][2]==matrix[1][1] && matrix[1][1]==matrix[2][0]) return matrix[0][2]; return ' '; }
Transformação de Matriz em Matriz Transposta
CALCULADORA DO IMC (VERSÃO C++)
Nenhum comentário foi encontrado.
Criar entrada (menuentry) ISO no Grub
Como gerar qualquer emoji ou símbolo unicode a partir do seu teclado
Instalar o VIM 9.1 no Debian 12
Como saber o range de um IP público?
Muitas dificuldades ao instalar distro Linux em Notebook Sony Vaio PCG-6131L (VPCEA24FM)
Slackpkg+ (Slackpkg Plus) está de volta!
Como dividir duas janelas igualmente e lado-a-lado na sua tela
Como redefinir o diretório Home? (4)
Problemas com adaptadores wifi no Zorin (1)
Ocomon 6.0.1 - Problemas ao editar configurações estendidas (7)