pablosotol

Ejercicio del juego del gato

May 26th, 2015
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.68 KB | None | 0 0
  1. include <stdio.h>
  2.  
  3. //Existe un problema con el la captura de caracteres en C, esto se puede solucionar llamando a la función limpia
  4. void limpia(){
  5.     char c=80;
  6.     while (c!='\n' && c!=EOF)
  7.         c= getchar();
  8.     return;
  9. }
  10. void mostrarGato(char gato[][3]){
  11.     int j, i;
  12.     printf ("\n     Juego el gato ^- . -^   \n " );
  13.     for (i = 0; i < 3  ; i ++){
  14.         for  (j = 0; j < 3   ; j ++){
  15.             printf ("\t%c", gato[i][j] );
  16.         }
  17.         printf ("\n ");
  18.     }
  19.    
  20. }
  21.  
  22. void limpiarTablero(char gato[][3]){
  23.     int i, j;
  24.     for (i = 0; i < 3  ; i ++){
  25.         for  (j = 0; j < 3   ; j ++) {
  26.             gato[i][j] = '-';
  27.         }
  28.     }
  29. }
  30.  
  31.  
  32. /* Que queda por hacer :
  33. Validar quien ganó después de cada ingreso
  34. generar un menu para ir jugando
  35. */
  36. int main (){
  37.     int i,j,x=0,opc;
  38.     char gato[3][3];
  39.     while(x!=1){
  40.           printf("Bienvenido al juego del gato seleccione una opcion: \n1)Jugar \n2)Salir ");
  41.           scanf("%d",&opc);
  42.           switch(opc){
  43.           case 1: limpiarTablero(gato);
  44.                   for(i=0;i<3;i++){
  45.                       for(j=0;j<3;j++){
  46.                           printf ("\nIngrese la posición donde quiere colocar sus datos \n");
  47.                           scanf("%d %d", &i, &j);
  48.                           printf ("\nIngrese X ó 0 (X jugador 1, 0 jugador 2, recuerde respetar los turnos) ");
  49.                           limpia();
  50.                           scanf("%c", &gato[i][j]);
  51.                           if(gato[0][0]=='O' && gato[0][1]=='O' && gato[0][2]=='O'){
  52.                              printf("\nGano el jugador que ocupaba la 0");
  53.                              x++;
  54.                           }
  55.                           if(gato[0][0]=='X' && gato[0][1]=='X' && gato[0][2]=='X'){
  56.                                  printf("\nGano el jugador que ocupaba la X");
  57.                              x++;
  58.                           }  
  59.                           if(gato[1][0]=='O' && gato[1][1]=='O' && gato[1][2]=='O'){
  60.                              printf("\nGano el jugador que ocupaba la O");
  61.                              x++;
  62.                           }
  63.                           if(gato[1][0]=='X' && gato[1][1]=='X' && gato[1][2]=='X'){
  64.                              printf("\nGano el jugador que ocupaba la X");
  65.                              x++;
  66.                           }
  67.                           if(gato[2][0]=='X' && gato[2][1]=='X' && gato[2][2]=='X'){
  68.                              printf("\nGano el jugador que ocupaba la X");
  69.                                  x++;
  70.                           }
  71.                           if(gato[2][0]=='O' && gato[2][1]=='O' && gato[2][2]=='O'){
  72.                              printf("\nGano el jugador que ocupaba la O");
  73.                                                  x++;                
  74.                           }
  75.                           if(gato[0][0]=='X' && gato[1][1]=='X' && gato[2][2]=='X'){
  76.                              printf("\nGano el jugador que ocupaba la X");
  77.                              x++;
  78.                           }
  79.                           if(gato[0][0]=='O' && gato[1][1]=='O' && gato[2][2]=='O'){
  80.                               printf("\nGano el jugador que ocupaba la O");
  81.                               x++;
  82.                           }
  83.                           if(gato[0][0]=='X' && gato[1][0]=='X' && gato [2][0]=='X'){
  84.                               printf("\nGano el jugador que ocupaba la X");
  85.                               x++;
  86.                           }
  87.                           if(gato[0][0]=='O' && gato[1][0]=='O' && gato [2][0]=='O'){
  88.                               printf("\nGano el jugador que ocupaba la X");
  89.                               x++;
  90.                           }
  91.                           if(gato[0][1]=='O' && gato[1][1]=='O' && gato[2][1]=='O'){
  92.                              printf("\nGano el jugador que ocupaba la O");
  93.                                  x++;
  94.                                                   }
  95.                           if(gato[0][1]=='X' && gato[1][1]=='X' && gato[2][1]=='X'){
  96.                               printf("\nGano el jugador que ocupaba la X");
  97.                                   x++;
  98.                                                   }
  99.                           if(gato[0][2]=='X' && gato[1][2]=='X' && gato[2][2]=='X'){
  100.                               printf("\nGano el jugador que ocupaba la X");
  101.                                   x++;
  102.                                                   }
  103.                           if(gato[0][2]=='O' && gato[1][2]=='O' && gato[2][2]=='O'){
  104.                               printf("\nGano el jugador que ocupaba la O");
  105.                                                           x++;
  106.                           }
  107.               }
  108.               }      
  109.                   mostrarGato(gato);
  110.           break;
  111.           case 2: x++;
  112.           break;
  113.          
  114.     }
  115.    
  116.    
  117.     return 0;
  118. }
  119. }
Advertisement
Add Comment
Please, Sign In to add comment