elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Rompecabezas de Bitcoin, Medio millón USD en premios


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación C/C++ (Moderadores: Eternal Idol, Littlehorse, K-YreX)
| | |-+  Ayuda! Problema de un menu!!!
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: 1 [2] Ir Abajo Respuesta Imprimir
Autor Tema: Ayuda! Problema de un menu!!!  (Leído 4,274 veces)
eferion


Desconectado Desconectado

Mensajes: 1.248


Ver Perfil
Re: Ayuda! Problema de un menu!!!
« Respuesta #10 en: 3 Julio 2013, 17:46 pm »

Me refería a algo más o menos así...

Fíjate que mi main tiene unas 40 líneas frente a las 200 del tuyo... aparte de que el mío funciona jejejeje.

Serás capaz de terminarlo??

Hay cosas que habría hecho de forma diferente, pero he intentado mantener el estilo de tu programa.

Código
  1. //* JUEGO CONECTA 4*//
  2.  
  3. /*Librerias utilizadas*/
  4. #include <stdlib.h>
  5. #include <stdio.h>
  6. #include <string.h>
  7.  
  8. #define LENGTH_JUGADOR    40
  9. #define LENGTH_CEDULA     8
  10. #define MAX_PARTIDAS      20
  11. #define DIM               16 //Constante utilizada para definir la maxima dimension del tablero
  12.  
  13. /* Estructuras */
  14.  
  15. struct jugador
  16. {
  17.  char nom_jug[ LENGTH_JUGADOR + 1 ];
  18.  char ced_jug[ LENGTH_CEDULA + 1 ];
  19. };
  20.  
  21. struct partida
  22. {
  23.  // Para almacenar los datos del jugador1
  24.  struct jugador jugador1;
  25.  
  26.  // Para almacenar los datos del jugador2
  27.  struct jugador jugador2;
  28.  
  29.  // Almacena 1 ( ganador jugador 1 ) o 2 ( ganador jugador 2 ).
  30.  int ganador;
  31. };
  32.  
  33. struct manager_partidas
  34. {
  35.  // Almacena todas las partidas jugadas
  36.  struct partida partidas[ MAX_PARTIDAS ];
  37.  
  38.  // Indica la partida actual
  39.  int num_partida;
  40. };
  41.  
  42. /*PROCEDIMIENTOS Y FUNCIONES*/
  43.  
  44. void pausa( );
  45. int mostrar_menu( int );
  46. int calcula_numero_jugadores( struct partida* );
  47. void pedir_datos_jugador( struct jugador* );
  48. void mostrar_resultados( struct manager_partidas* );
  49.  
  50. void inicializar_tablero(char tablero[][DIM],int);
  51. int juegan_O_(char tabla[][DIM],int,int);
  52. int juegan_X_(char tablero[][DIM],int,int);
  53. int cuatro_en_linea(char tablero[][DIM],int);
  54. int limpiar(char nom_jug[]);
  55.  
  56. int main()
  57. {
  58.  char tablero[ DIM ][ DIM ];
  59.  int numero_jugadores = 0;
  60.  int opcion = -1;
  61.  
  62.  // Se inicializa la estructura de las partidas
  63.  struct manager_partidas manager;
  64.  memset( &manager, 0, sizeof( manager ) );
  65.  
  66.  while ( opcion != 5 )
  67.  {
  68.    // Puntero a la partida actual... para evitar líneas de código
  69.    struct partida* partida_actual = &manager.partidas[ manager.num_partida ];
  70.  
  71.    // Se comprueba el número de jugadores en la partida actual
  72.    numero_jugadores = calcula_numero_jugadores( partida_actual );
  73.  
  74.    opcion = mostrar_menu( numero_jugadores );
  75.  
  76.    switch ( opcion )
  77.    {
  78.      case 1:
  79.        pedir_datos_jugador( &partida_actual->jugador1 );
  80.        break;
  81.  
  82.      case 2:
  83.        pedir_datos_jugador( &partida_actual->jugador2 );
  84.        break;
  85.  
  86.      case 3:
  87.        // Se simula una partida, para ello se elige un ganador
  88.        // y se incrementa el contador de la partida
  89.        partida_actual->ganador = ( manager.num_partida % 2 );
  90.        ++manager.num_partida;
  91.  
  92.        // Jugar
  93.        break;
  94.  
  95.      case 4:
  96.        // Se pasa una referencia para no copiar toda la estructura
  97.        mostrar_resultados( &manager );
  98.        break;
  99.  
  100.      case 5:
  101.        break;
  102.    }
  103.  }
  104. }
  105.  
  106. void pausa( )
  107. {
  108.  printf( "\nPulse una tecla para continuar..." );
  109.  fseek( stdin, 0, SEEK_END);
  110.  getchar( );
  111. }
  112.  
  113. int mostrar_menu( int numero_jugadores )
  114. {
  115.  int ok = 0;
  116.  int opcion = -1;
  117.  
  118.  while ( !ok )
  119.  {
  120.    // Limpiamos el buffer, por si acaso
  121.    fseek( stdin, 0, SEEK_END);
  122.  
  123.    system( "cls" );
  124.    printf( "\n\n\n     JUEGO CUATRO EN LINEA\n\n\n\n\n" );
  125.    printf( "  1) Ingresar datos del primer jugador\n\n" );
  126.    printf( "  2) Ingresar datos del segundo jugador\n\n" );
  127.    printf( "  3) Jugar\n\n" );
  128.    printf( "  4) Listar todos los juegos realizados\n\n" );
  129.    printf( "  5) Salir\n\n\n" );
  130.  
  131.    if ( opcion == 3 )
  132.    {
  133.      printf( "  Error: Antes de jugar debe ingresar los datos de los dos jugadores. \n\n\n" );
  134.      printf( "  REINGRESE SU OPCION: " );
  135.    }
  136.    else if ( opcion != -1 )
  137.    {
  138.      printf( "  Opcion incorrecta \n\n\n" );
  139.      printf( "  REINGRESE SU OPCION: " );
  140.    }
  141.    else
  142.    {
  143.      printf( "INGRESE SU OPCION: " );
  144.    }
  145.  
  146.    scanf( "%d", &opcion );
  147.    if ( opcion == 3 )
  148.      ok = ( numero_jugadores == 2 );
  149.    else
  150.      ok = ( opcion > 0 && opcion < 6 );
  151.  }
  152.  
  153.  return opcion;
  154. }
  155.  
  156.  
  157. int calcula_numero_jugadores( struct partida* partida )
  158. {
  159.  int jugadores = 0;
  160.  
  161.  if ( partida->jugador1.nom_jug[ 0 ] != '\0' )
  162.    ++jugadores;
  163.  
  164.  if ( partida->jugador2.nom_jug[ 0 ] != '\0' )
  165.    ++jugadores;
  166.  
  167.  return jugadores;
  168. }
  169.  
  170.  
  171. void pedir_datos_jugador( struct jugador* jugador )
  172. {
  173.  int ok = 0;
  174.  
  175.  while ( !ok )
  176.  {
  177.    // Se limpia el buffer de entrada.
  178.    fseek( stdin, 0, SEEK_END);
  179.  
  180.    printf( "\n Ingrese su Nombre: " );
  181.    scanf("%40[^\n]", jugador->nom_jug );
  182.    ok = ( jugador->nom_jug[ 0 ] != '\0' );
  183.  
  184.    if ( !ok )
  185.      printf("\n ERROR" );
  186.  }
  187.  
  188.  ok = 0;
  189.  while ( !ok )
  190.  {
  191.    // Se limpia el buffer de entrada.
  192.    fseek( stdin, 0, SEEK_END);
  193.  
  194.    printf( "\n Ingrese su cedula: " );
  195.    scanf("%40[^\n]", jugador->ced_jug );
  196.    ok = ( jugador->ced_jug[ 0 ] != '\0' );
  197.  
  198.    if ( !ok )
  199.      printf("\n ERROR" );
  200.  }
  201.  
  202.  pausa( );
  203. }
  204.  
  205. void mostrar_resultados( struct manager_partidas* manager )
  206. {
  207.  if ( manager->num_partida == 0 )
  208.  {
  209.    printf ( "No se han jugador partidas." );
  210.  }
  211.  else
  212.  {
  213.    int i;
  214.    for ( i=0; i<manager->num_partida; ++i )
  215.    {
  216.      printf( "Partida %d\n", i+1 );
  217.      printf( "\n");
  218.      printf( "Jugador 1: %s\n", manager->partidas[ i ].jugador1.nom_jug );
  219.      printf( "Cedula:    %s\n", manager->partidas[ i ].jugador1.ced_jug );
  220.      printf( "Jugador 2: %s\n", manager->partidas[ i ].jugador2.nom_jug );
  221.      printf( "Cedula:    %s\n", manager->partidas[ i ].jugador2.ced_jug );
  222.      printf( "Ganador jugador %d\n\n", manager->partidas[ i ].ganador );
  223.    }
  224.  }
  225.  
  226.  pausa( );
  227. }


En línea

mathias_vg

Desconectado Desconectado

Mensajes: 39


Ver Perfil
Re: Ayuda! Problema de un menu!!!
« Respuesta #11 en: 4 Julio 2013, 20:09 pm »

Bueno eh podido hacer que me almacene las partidas pero lo que no puedo es que me indique el ganador de cada partida alguien me puede ayudar con esto?


Muchas gracias

Nota : en la linea 200 me tira un error cuando cito a la funcion 4 en linea, algeuin sabe porque es?



Código
  1.  
  2.    //* JUEGO CUATRO EN LINEA*//
  3.  
  4.  
  5.   /*MATHIAS CASTRO*/
  6.    /*4.523.221-8*/
  7.  
  8. /*Librerias utilizadas*/
  9. #include <stdlib.h>
  10. #include <stdio.h>
  11. #define DIM 16 /*Constante utilizada para definir la maxima dimension del tablero*/
  12. //#define tam_string 40 /*Constante para la cantidad de digitos de los Nombres*/
  13. //#define ced_string 8
  14.  
  15.  
  16. struct jugador1{
  17.        char nom_jug1[40];
  18.        char ced_jug1[8];
  19.    }jugador1[500];
  20. struct jugador2{
  21.        char nom_jug2[40];
  22.        char ced_jug2[8];
  23.    }jugador2[500];
  24. struct ganadores{
  25.        char jganador;
  26.    }ganadores[1000];
  27.  
  28. /*PROCEDIMIENTOS Y FUNCIONES*/
  29.  
  30. void inicializar_tablero(char tablero[][DIM],int);
  31. int juegan_O_(char tabla[][DIM],int,int);
  32. int juegan_X_(char tablero[][DIM],int,int);
  33. int cuatro_en_linea(char tablero[][DIM],int);
  34. int limpiar(char nom_jug[]);
  35.  
  36. char nom_jug1[40];
  37. char nom_jug2[40];
  38. char ced_jug1[8];
  39. char ced_jug2[8];
  40. int player1 = 0, player2 = 0;
  41. int main()
  42. {
  43.  
  44.  
  45.  
  46.    char tablero[DIM][DIM];
  47.  
  48.    int x,opcion,victoria=1,nombre1,nombre2,contador=1,correcta=1,aux=1,sumador = 0;
  49.    int ganador=0,temp = 0;
  50.    int part, aux2,aux3;
  51.    do
  52. {
  53. system("cls");
  54.    printf("\n\n\n     JUEGO CUATRO EN LINEA\n\n\n\n\n");
  55.    printf("  1) Ingresar datos del primer jugador\n\n");
  56.    printf("  2) Ingresar datos del segundo jugador\n\n");
  57.    printf("  3) Jugar\n\n");
  58.    printf("  4) Listar todos los juegos realizados\n\n");
  59.    printf("  5) Salir\n\n\n");
  60.    if (contador%2==0)
  61.     {
  62.     printf("  Error: Antes de jugar debe ingresar los datos de los dos jugadores. \n\n\n");
  63.     printf("  REINGRESE SU OPCION: ");
  64. contador--;
  65.     }
  66.     if (correcta%2==0)
  67.     {
  68.     printf("  Opcion incorrecta \n\n\n");
  69.     printf("  REINGRESE SU OPCION: ");
  70.     correcta--;
  71.     }
  72.     if (aux%2==0)
  73.     {
  74.     printf("  No se han realizado juegos. \n\n\n");
  75.     aux--;
  76.     }
  77.  
  78.    scanf("%d",&opcion);
  79.    system("cls");
  80.    switch (opcion)
  81.    {
  82.    case 1:  /*OPCION 1 DEL MENU*/
  83.    {
  84.     limpiar(nom_jug1);
  85.     limpiar(ced_jug1);
  86.     while(getchar() != '\n');
  87.     printf("\n Ingrese su Nombre: ");
  88.     do
  89.     {
  90.     scanf("%39[^\n]",jugador1[player1].nom_jug1);
  91.     if (jugador1[player1].nom_jug1[0]=='\0')
  92.     {
  93.     printf(" ERROR\n");
  94.     printf(" Ingrese nuevamente Nombre: ");
  95.     }
  96. else
  97. {
  98.  
  99. for (nombre1=0;nombre1<40;nombre1++)
  100.     {
  101.     nom_jug1[nombre1];
  102.     }
  103. }while(getchar() != '\n');
  104. system("cls");
  105.        }while(jugador1[player1].nom_jug1[0]=='\0');
  106.     printf("\n Ingrese su cedula: ");
  107.     do
  108.     {
  109.     scanf("%8[^\n]",jugador1[player1].ced_jug1);    
  110.     if (jugador1[player1].ced_jug1[0]=='\0')
  111.     {
  112.     printf(" ERROR\n");
  113.     printf(" Ingrese nuevamente su cedula: ");
  114.     }
  115. else
  116. {
  117.  
  118. for (nombre1=0;nombre1<8;nombre1++)
  119.     {
  120.     ced_jug1[nombre1];
  121.     }
  122.        system("cls");
  123.     printf("\n");
  124. }while(getchar() != '\n');
  125.        }while(jugador1[player1].ced_jug1[0]=='\0');
  126.        printf("\n    DATOS INGRESADOS\n");
  127.        printf("\n\n   Nombre ingresado: %s",jugador1[player1].nom_jug1);
  128.     printf("\n\n   Cedula ingresada: %s",jugador1[player1].ced_jug1);
  129.     printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n presione ENTER para volver al menu");
  130.     jugador1[player1+1]=jugador1[player1];
  131.     break;
  132.    }
  133.    case 2:  /*OPCION 2 DEL MENU*/
  134.    {
  135. limpiar(nom_jug2);
  136.     limpiar(ced_jug2);
  137.     while(getchar() != '\n');
  138.     printf("\n Ingrese su Nombre: ");
  139.     do
  140.     {
  141.     scanf("%39[^\n]",jugador2[player2].nom_jug2);
  142.     if (jugador2[player2].nom_jug2[0]=='\0')
  143.     {
  144.     printf(" ERROR\n");
  145.     printf(" Ingrese nuevamente Nombre: ");
  146.     }
  147. else
  148. {
  149.  
  150. for (nombre2=0;nombre2<40;nombre2++)
  151.     {
  152.     nom_jug2[nombre2];
  153.     }
  154. }while(getchar() != '\n');
  155. system("cls");
  156.        }while(jugador2[player2].nom_jug2[0]=='\0');
  157.     printf("\n Ingrese su cedula: ");
  158.     do
  159.     {
  160.     scanf("%8[^\n]",jugador2[player2].ced_jug2);  
  161. do
  162.  
  163.     if (jugador2[player2].ced_jug2[0]=='\0')
  164.     {
  165.     printf(" ERROR\n");
  166.     printf(" Ingrese nuevamente su cedula: ");
  167.     }
  168. else
  169. {
  170.  
  171. for (nombre2=0;nombre2<8;nombre2++)
  172.     {
  173.     ced_jug2[nombre2];
  174.     }
  175.     system("cls");
  176.     printf("\n");
  177. }while(getchar() != '\n');
  178.        }while(jugador2[player2].ced_jug2[0]=='\0');
  179.  
  180.        printf("\n    DATOS INGRESADOS\n");
  181.        printf("\n\n   Nombre ingresado: %s",jugador2[player2].nom_jug2);
  182.     printf("\n\n   Cedula ingresada: %s",jugador2[player2].ced_jug2);
  183.     printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n presione ENTER para volver al menu");
  184.  
  185.     jugador2[player2+1]=jugador2[player2];
  186.     break;
  187.    }
  188.    case 3: /*OPCION 3 DEL MENU*/
  189.     {
  190.     if ((jugador1[player1].nom_jug1[0]=='\0') || (jugador2[player2].nom_jug2[0]=='\0'))
  191.     {
  192.     contador++;
  193.  
  194.     }
  195.     else  
  196.     {
  197.        cuatro_en_linea(tablero,opcion);
  198.        sumador++;
  199.        ganadores[ganador].jganador=cuatro_en_linea();
  200.                    ganador++;
  201.        if(jugador1[player1].nom_jug1[40]==jugador1[player1+1].nom_jug1[40]){
  202.                        jugador1[player1+2]=jugador1[player1+1];
  203.                        player1++;
  204.                    }
  205.                    if(jugador2[player2].nom_jug2[40]==jugador2[player2+1].nom_jug2[40]){
  206.                        jugador2[player2+2]=jugador2[player2+1];
  207.                        player2++;
  208.                    }
  209.        }
  210.        break;
  211.    }
  212.    case 4:
  213.     if (sumador<1)
  214.     {
  215.     aux++;
  216.     }
  217.     else
  218.     {
  219.            part=1;
  220.            aux2=0;
  221.            aux3 = 0;
  222.            for(aux2=0;aux2<sumador;aux2++){
  223.            printf("Partida %d\n",part);
  224.            part++;
  225.            printf("Jugador 1: %s\n",jugador1[aux2].nom_jug1);
  226.            printf("Cedula:    %s\n",jugador1[aux2].ced_jug1);
  227.            printf("Jugador 2: %s\n",jugador2[aux2].nom_jug2);
  228.            printf("Cedula:    %s\n",jugador2[aux2].ced_jug2);
  229.            if (ganadores[aux3].jganador == 1)
  230.            {
  231.                printf("Gana el jugador 1");
  232.            }
  233.            else if (ganadores[aux3].jganador == 2)
  234.            {
  235.                printf("Gana el jugador 2");
  236.            }
  237.            else if (ganadores[aux3].jganador == 0)
  238.            {
  239.            printf("EMPATE");
  240.            }
  241.     }
  242.     system("PAUSE");
  243.     }
  244.     break;
  245.    case 5: /*OPCION 5 DEL MENU*/
  246.     return printf("\n\n  SALIENDO\n\n");
  247.     break;
  248.    default:
  249.     correcta++;
  250.     break;
  251.    }while (getchar()!='\n');
  252.    }while (victoria==1);
  253. }
  254. int cuatro_en_linea(char tablero[DIM][DIM],int x)
  255. {
  256.  
  257.    /*Defino distintas variables que voy a utilizar a lo largo del programa*/
  258.    int n=0,i,j,resto=1,k=0,jugador,partida,victoria=0;
  259.    char d;
  260.    printf("\n\nIngresa la dimension del tablero de juego(4-15): ");
  261.    /*Analizamos si la dimension del tablero ingresada es valida*/
  262.    do
  263.    {
  264.        scanf (" %d",&x);
  265.        system("cls");
  266.        if (x<4 || x>15)
  267.        {
  268.            printf("\nOpcion no valida. Ingresa la dimension (4-15): ");
  269.        }   while (getchar()!='\n');
  270.    } while (x<4 || x>15);
  271.    system("cls");
  272.    /*Elegimos judagor*/
  273.    printf("\n ELIJA JUGADOR\n\n\n");
  274.    printf("\n\n  1) JUGADOR 1 (X)\n");
  275.    printf("\n\n  2) JUGADOR 2 (O)\n");
  276.    do
  277.    {
  278.    scanf("%d",&jugador);
  279.    if ((jugador!=1) && (jugador!=2))
  280.    {
  281.        printf("\n Error: Los jugadores posibles son 1 y 2 ");
  282.    }
  283.    }while ((getchar()!='\n') || ((jugador!=1) && (jugador!=2)));
  284.    do
  285.    {
  286.        system("cls");
  287.        printf("\n\n\n\n");
  288.        inicializar_tablero(tablero,x);
  289.        while ((resto<=(x*x)) && (victoria!=1))
  290.        {
  291.            if (jugador==1)
  292.            {
  293.                jugador++;
  294.               juegan_X_(tablero,x,n);
  295.               /* Evaluo si el jugador 1 (X) gana*/
  296.  
  297.               for (i=1;i<=x;i++)
  298.           {
  299.     for (j=1;j<=x;j++)
  300. {
  301.                        /*Verifico si hay cuatro en linea horizontal para Jugador 1*/
  302. if ((tablero[i][j]=='X') && ((tablero[i][j+1])=='X') && ((tablero[i][j+2])=='X') && ((tablero[i][j+3])=='X'))
  303. {
  304. victoria = 1;
  305. }        
  306. /*Verifico si hay cuatro en linea vertical para Jugador 1*/
  307. else if ((tablero[i][j]=='X') && ((tablero[i+1][j])=='X') && ((tablero[i+2][j])=='X') && ((tablero[i+3][j])=='X'))
  308. {
  309. victoria = 1;
  310. }
  311. /*Verifico si hay cuatro en linea en diagonal ascendiente para Jugador 1*/
  312. else if ((tablero[i][j]=='X') && ((tablero[i+1][j-1])=='X') && ((tablero[i+2][j-2])=='X') && ((tablero[i+3][j-3])=='X'))
  313. {
  314. victoria = 1;
  315. }
  316. /*Verifico si hay cuatro en linea en diagonal descendiente para Jugador 1*/
  317. else if ((tablero[i][j]=='X') && ((tablero[i+1][j+1])=='X') && ((tablero[i+2][j+2])=='X') && ((tablero[i+3][j+3])=='X'))
  318. {
  319. victoria = 1;
  320. }
  321. }
  322.   }
  323.               if (victoria == 1)
  324.               {
  325.               printf("\n\n FELICITACIONES %s",nom_jug1);
  326.               printf("!!!\n\n  Has ganado la partida.\n\n\n\n\n\n");
  327.               return 1;
  328.               }
  329.               else
  330.               {
  331.               resto++;
  332.               }
  333.            }
  334.            else if (jugador == 2)
  335.            {
  336.                jugador--;
  337. juegan_O_(tablero,x,n);
  338. /* Evaluo si el jugador 2 (O) gana*/
  339.  
  340. for (i=1;i<=x;i++)
  341.           {
  342.     for (j=1;j<=x;j++)
  343. {
  344.                        /*Verifico si hay cuatro en linea horizontal para Jugador 1*/
  345. if ((tablero[i][j]=='O') && ((tablero[i][j+1])=='O') && ((tablero[i][j+2])=='O') && ((tablero[i][j+3])=='O'))
  346. {
  347. victoria = 1;
  348. }
  349. /*Verifico si hay cuatro en linea vertical para Jugador 1*/
  350. else if ((tablero[i][j]=='O') && ((tablero[i+1][j])=='O') && ((tablero[i+2][j])=='O') && ((tablero[i+3][j])=='O'))
  351. {
  352. victoria = 1;
  353. }
  354. /*Verifico si hay cuatro en linea en diagonal ascendiente para Jugador 2*/
  355. else if ((tablero[i][j]=='O') && ((tablero[i+1][j-1])=='O') && ((tablero[i+2][j-2])=='O') && ((tablero[i+3][j-3])=='O'))
  356. {
  357. victoria = 1;
  358. }
  359. /*Verifico si hay cuatro en linea en diagonal descendiente para Jugador 2*/
  360. else if ((tablero[i][j]=='O') && ((tablero[i+1][j+1])=='O') && ((tablero[i+2][j+2])=='O') && ((tablero[i+3][j+3])=='O'))
  361. {
  362. victoria = 1;
  363. }
  364. }
  365.   }
  366.               if (victoria == 1)
  367.               {
  368.               printf("\n\n FELICITACIONES %s",nom_jug2);
  369.               printf("!!!\n\n  Has ganado la partida.\n\n\n\n\n\n");
  370.               return 2;
  371.               }
  372.               else
  373.               {  
  374.                resto++;
  375.               }
  376.            }
  377.  
  378.            /*Si el tablero se lleno de fichas y no hay cuatro en linea
  379.             el partido termina en empate*/
  380.  
  381.            if (resto > (x*x) && (victoria!=1))
  382.         {
  383.         printf("\n\n EMPATE\n\n");
  384.         return 0;
  385.            }
  386.        }
  387.    }while ((resto<=(x*x)) && (victoria!=1));
  388.    system("PAUSE");
  389.    resto = 1;
  390.    victoria = 0;
  391.    system("cls");
  392.    inicializar_tablero(tablero,x);
  393.    system("cls");
  394. }
  395. /* Procedimiento para imprimir el tablero inicial*/
  396.  
  397. void inicializar_tablero(char tablero[DIM][DIM],int x)
  398. {
  399. int i,j;
  400. int contador = 1;
  401. for (i=1; i<=x; i++)
  402. {
  403. for (j=1;j<=x; j++)
  404. {
  405.            printf("  ");
  406. printf(" %c",tablero[i][j]='.');
  407. }
  408. printf("\n\n");
  409.  
  410. }
  411. for (i=1;i<=x;i++)
  412. {
  413.        printf("   %d",contador);
  414.        contador++;
  415.    }
  416.    printf("\n");
  417. }
  418. /*Funcion para hacer jugada para el jugador 1*/
  419.  
  420. int juegan_X_(char tablero[DIM][DIM],int x,int n)
  421. {
  422. int i,j,k,contador=1;
  423. do
  424.    {
  425.        printf("\n\n Juega %s: ",nom_jug1);
  426.                    scanf ("%d",&n);
  427.        if (n<1 || n>x)
  428.        {
  429.            printf("Error: las columnas posibles son de 1 a %d",x);
  430.            while (getchar()!='\n');
  431.        }  
  432. else if (tablero[1][n]!='.')
  433. {
  434. printf("\nError: la columna ya esta llena.\n ");
  435.     }
  436.    }while((n<1 || n>x) || (tablero[1][n]!='.'));
  437. for (k=x;k>=1;k--)
  438.    {
  439.            if (tablero[k][n]!='.')
  440.            {
  441.                continue;
  442.            }
  443.            else
  444.            {
  445.                tablero[k][n]='X';
  446.                break;
  447.            }
  448.    }
  449.       system("cls");  
  450.   printf("\n Ultima jugada X: Columna %d\n",n);      
  451.    printf("\n\n");
  452.    for (i=1;i<=x;i++)
  453.    {
  454.        for (j=1;j<=x;j++)
  455.        {
  456.            printf("  ");
  457.            printf (" %c",tablero[i][j]);
  458.  
  459.        }
  460.        printf("\n\n");
  461.    }
  462.    for (i=1;i<=x;i++)
  463. {
  464.        printf("   %d",contador);
  465.        contador++;
  466.    }
  467.    printf("\n");
  468. }
  469. /*Funcion para hacer jugada para el jugador 2*/
  470.  
  471. int juegan_O_(char tablero[DIM][DIM],int x,int n)
  472. {
  473. int i,j,k,contador=1;
  474. do
  475.    {
  476.        printf("\n\n Juega %s: ",nom_jug2);
  477.                    scanf ("%d",&n);
  478.        if (n<1 || n>x)
  479.        {
  480.            printf("Error: las columnas posibles son de 1 a %d",x);
  481.            while (getchar()!='\n');
  482.        }  
  483. else if (tablero[1][n]!='.')
  484. {
  485. printf("\nError: la columna ya esta llena.\n ");
  486.     }
  487.    }while((n<1 || n>x) || (tablero[1][n]!='.'));
  488. for (k=x;k>=1;k--)
  489.    {
  490.            if (tablero[k][n]!='.')
  491.            {
  492.                continue;
  493.            }
  494.            else
  495.            {
  496.                tablero[k][n]='O';
  497.                break;
  498.            }
  499.    }
  500.    system("cls");    
  501. printf("\n Ultima jugada O: Columna %d\n",n);    
  502.    printf("\n\n");
  503.    for (i=1;i<=x;i++)
  504.    {
  505.        for (j=1;j<=x;j++)
  506.        {
  507.            printf("  ");
  508.            printf (" %c",tablero[i][j]);
  509.  
  510.        }
  511.        printf("\n\n");
  512.    }
  513.    for (i=1;i<=x;i++)
  514. {
  515.        printf("   %d",contador);
  516.        contador++;
  517.    }
  518.    printf("\n");
  519. }
  520. int limpiar(char nom_jug[40])
  521. {
  522.  
  523. int t;
  524. for (t=0; t<40; t++)
  525.    {
  526.     nom_jug[t]='\0';
  527.    }
  528. }
  529.  
  530.  
  531.  
  532.  
  533.  


En línea

eferion


Desconectado Desconectado

Mensajes: 1.248


Ver Perfil
Re: Ayuda! Problema de un menu!!!
« Respuesta #12 en: 4 Julio 2013, 21:08 pm »

Vaya, veo que no has usado nada de lo que te puse... la próxima vez me ahorro el esfuerzo.

Código
  1.        cuatro_en_linea(tablero,opcion);
  2.        sumador++;
  3.        ganadores[ganador].jganador=cuatro_en_linea();

La función cuatro_en_linea sin argumentos no existe...

deberías eliminar la primera llamada y dejar la segunda, en la que estableces jganador, con los dos argumentos de la primera.
En línea

Páginas: 1 [2] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
problema con menu dvd
Multimedia
marisolsol 2 1,691 Último mensaje 5 Mayo 2005, 10:35 am
por marisolsol
Problema al hacer menu en avi « 1 2 »
Multimedia
Troll_Berserker_666 10 3,953 Último mensaje 14 Agosto 2007, 16:26 pm
por Troll_Berserker_666
como lleno los datos que tiene un menu a otro menu vacio, en asp.net c#
.NET (C#, VB.NET, ASP)
ivan05f 2 3,587 Último mensaje 8 Noviembre 2007, 18:58 pm
por ivan05f
problema con menu
Desarrollo Web
kakashi20 3 2,269 Último mensaje 4 Abril 2013, 14:20 pm
por #!drvy
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines