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

 

 


Tema destacado: Recuerda que debes registrarte en el foro para poder participar (preguntar y responder)


  Mostrar Mensajes
Páginas: 1 2 3 [4]
31  Programación / Programación C/C++ / Ayuda en: 6 Junio 2013, 21:18 pm
leosansan como estas?

Eh estado tratando de solucionar los problemas que me marcaste, mas precisamente que me imprima hacia arriba las jugadas pero no lo eh lo grado me podrias decir en que estoy fallando?

Cuelgo el codigo a continuacion

Muchas gracias


Código
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int main()
  4. {
  5.  
  6.    char d;
  7.    bool termino = false;
  8.    int n=0,i=0,j=0,dim1=0,dim2=0,resto=1,contador=1;
  9.    printf("\n\n\n     JUEGO CUATRO EN LINEA\n\n\n\n\n\n\n");
  10.    printf("       Nueva partida (S/N)  ");
  11.    scanf("%c",&d);
  12.    printf("\n");
  13.    printf("       JUGADOR 1  \n");
  14.    printf("       JUGADOR 2    ");
  15.    switch (d)
  16.    {
  17.        case 'N':case 'n':
  18.        termino = true;
  19.        break;
  20.         default: printf("\n\nError");
  21.        break;
  22.        case 'S': case's':
  23.    printf("\n\n\n\nIngresa la dimension del tablero de juego:\n\n");
  24.    scanf (" \n%d",&dim2);
  25.    dim1 = dim2;
  26.    char matriz[dim1][dim2];
  27.    do
  28.    {
  29.        for (i=1;i<=dim1;i++)
  30.        {
  31.            for (j=1;j<=dim2;j++)
  32.            {
  33.                if ((matriz[i][j]!='X') && (matriz[i][j]!='O'))
  34.                {
  35.                    printf("%c ",'.');
  36.                }
  37.                else
  38.                {
  39.                    printf ("%c ",'X');
  40.                }
  41.            }
  42.            printf("\n");
  43.        }
  44.        while (resto<=(dim2*dim2))
  45.        {
  46.         if ((resto%2)==0)
  47.        {
  48.         printf("\nJuega JUGADOR 1: ");
  49.         scanf (" %d",&n);
  50.            matriz[dim1][n]='O';
  51.            printf ("%c\n",matriz[dim1][n]);
  52.            for (i=1;i<=dim1;i++)
  53.            {
  54.            for (j=1;j<=dim2;j++)
  55.            {
  56.                  if ((matriz[i][j]=='X') || (matriz[i][j]=='O'))
  57.                {
  58.                   matriz[dim1-1][n]='O';   /* corregir */
  59.                }
  60.                if ((matriz[i][j]!='X') && (matriz[i][j]!='O'))
  61.                {
  62.                    printf("%c ",'.');
  63.                }
  64.                else
  65.                {
  66.                    if ((matriz[i][j]!='X') && (matriz[i][j]!='.'))
  67.                    {
  68. printf ("%c ",'O');
  69.                    }
  70. else
  71. {
  72.         printf ("%c ",'X');
  73.                    }
  74.                }
  75.            }
  76.            printf("\n");
  77.        }
  78.    }
  79.        else
  80.        {
  81.         printf("\nJuega JUGADOR 2: ");
  82.            scanf (" %d",&n);
  83.            matriz[dim1][n]='X';
  84.            printf ("%c\n",matriz[dim1][n]);
  85.            for (i=1;i<=dim1;i++)
  86.        {
  87.            for (j=1;j<=dim2;j++)
  88.            {
  89.                 if ((matriz[i][j]=='X') || (matriz[i][j]=='O'))
  90.                {
  91.                   matriz[dim1-1][n]='X';   /* corregir */
  92.                }
  93.                if ((matriz[i][j]!='X') && (matriz[i][j]!='O'))
  94.                {
  95.                    printf("%c ",'.');
  96.                }
  97.                else
  98.                {
  99.                if ((matriz[i][j]!='X') && (matriz[i][j]!='.'))
  100.                {
  101. printf ("%c ",'O');
  102.                }
  103. else
  104. {
  105.     printf ("%c ",'X');
  106.                    }
  107.                }
  108.  
  109.            }
  110.            printf("\n");
  111.        }
  112.        }
  113.        resto++;
  114.        }
  115.        printf("EMPATE\n\n");
  116.        system("PAUSE");
  117.     }while (1);
  118.    return 0;
  119.    break;
  120.  
  121.    }
  122.    while (!termino);
  123. }
  124.  
  125.  
32  Programación / Programación C/C++ / Re: Juego 4 en linea. Ayuda!!! en: 5 Junio 2013, 21:18 pm
leosansan, eh estado tratando de seguir con el juego y hasta ahora he avanzado un poco aca abajo te cuelgo lo que puede hacer, a ver que tan bien esta o que me podes sugerir.

Nota en el juego fije la coordenada Y (dim) porque tengo que colocar la ficha en el lugar mas bajo posible.

Aguardo tus comentarios, saludos!!!

Código
  1. #include <stdio.h>
  2. #include <iostream.h>
  3. int main()
  4. {
  5.  
  6.    char d;
  7.    printf("\n\n\n     JUEGO CUATRO EN LINEA\n\n\n\n\n\n\n");
  8.    printf("       Nueva partida (S/N)");
  9.    scanf("%c",&d);
  10.    int n=0,i=0,j=0,dim=0,resto=0;
  11.    printf("\n\n\n\nIngresa la dimension del tablero de juego:\n\n");
  12.    scanf (" \n%d",&dim);
  13.    char matriz[dim][dim];
  14.    do
  15.    {
  16.        for (i=1;i<=dim;i++)
  17.        {
  18.            for (j=1;j<=dim;j++)
  19.            {
  20.                if ((matriz[i][j]!='X') && (matriz[i][j]!='O'))
  21.                    printf("%c ",'.');
  22.                else
  23.                    printf ("%c ",'X');
  24.            }
  25.            printf("\n");
  26.        }
  27.        while (resto<=(dim*dim))
  28.        {
  29.         if ((resto%2)==0)
  30.        {
  31.         printf("\nJuega JUGADOR 1: ");
  32.         scanf (" %d",&n);
  33.            matriz[dim][n]='O';
  34.            printf ("%c\n",matriz[dim][n]);
  35.            for (i=1;i<=dim;i++)
  36.        {
  37.            for (j=1;j<=dim;j++)
  38.            {
  39.                if ((matriz[i][j]!='X') && (matriz[i][j]!='O'))
  40.                    printf("%c ",'.');
  41.                else
  42.                    if ((matriz[i][j]!='X') && (matriz[i][j]!='.'))
  43. printf ("%c ",'O');
  44. else
  45. printf ("%c ",'X');
  46.            }
  47.            printf("\n");
  48.        }
  49.        }
  50.        else
  51.        {
  52.         printf("\nJuega JUGADOR 2: ");
  53.            scanf (" %d",&n);
  54.            matriz[dim][n]='X';
  55.            printf ("%c\n",matriz[dim][n]);
  56.            for (i=1;i<=dim;i++)
  57.        {
  58.            for (j=1;j<=dim;j++)
  59.            {
  60.                if ((matriz[i][j]!='X') && (matriz[i][j]!='O'))
  61.                    printf("%c ",'.');
  62.                else
  63.                if ((matriz[i][j]!='X') && (matriz[i][j]!='.'))
  64. printf ("%c ",'O');
  65. else
  66. printf ("%c ",'X');
  67.  
  68.            }
  69.            printf("\n");
  70.        }
  71.        }
  72.        resto++;
  73.        }
  74.  
  75.     }while (1);
  76.    return 0;
  77.    system("PAUSE");
  78. }
  79.  
  80.  
33  Programación / Programación C/C++ / Re: Juego 4 en linea. Ayuda!!! en: 5 Junio 2013, 16:48 pm
Ok voy a tratar de verlo con algun compañero de clase que han tenido el mismo problema pero creo que lograron solucionarlo, cualquier cosa te comento luego para ver bien en que quedo esto jeje.

Saludos!!! y una vez mas gracias jeej
34  Programación / Programación C/C++ / Re: Juego 4 en linea. Ayuda!!! en: 5 Junio 2013, 16:05 pm
Ok, espero tu respuesta. muchas gracias por tu tiempo leosansan. Saludos!
35  Programación / Programación C/C++ / Re: Juego 4 en linea. Ayuda!!! en: 5 Junio 2013, 15:52 pm
Si uso DevC++, debido a que me piden que se entregue para que funcione con ese compilador. Como puedo hacer para que me funcione en DevC++?

Muchas Gracias
36  Programación / Programación C/C++ / Re: Juego 4 en linea. Ayuda!!! en: 5 Junio 2013, 14:27 pm
Código
  1. \Documents and Settings\MatiasC\Escritorio\Practico 1 Soluciones\Sin Nombre1.cpp 7 C:\Documents and Settings\MatiasC\Escritorio\Practico 1 Soluciones\C [Error] variable-size type declared outside of any function
  2. \Documents and Settings\MatiasC\Escritorio\Practico 1 Soluciones\Sin Nombre1.cpp 7 C:\Documents and Settings\MatiasC\Escritorio\Practico 1 Soluciones\C [Error] variable-size type declared outside of any function
  3. \Documents and Settings\MatiasC\Escritorio\Practico 1 Soluciones\Sin Nombre1.cpp 8 C:\Documents and Settings\MatiasC\Escritorio\Practico 1 Soluciones\C [Error] variable-size type declared outside of any function
  4. \Documents and Settings\MatiasC\Escritorio\Practico 1 Soluciones\Sin Nombre1.cpp 8 C:\Documents and Settings\MatiasC\Escritorio\Practico 1 Soluciones\C [Error] variable-size type declared outside of any function
  5. In function `int main()':
  6. \Documents and Settings\MatiasC\Escritorio\Practico 1 Soluciones\Sin Nombre1.cpp 46 C:\Documents and Settings\MatiasC\Escritorio\Practico 1 Soluciones\C [Error] `dibujar_tablero' undeclared (first use this function)
  7. 46 [Error] (Each undeclared identifier is reported only once for each function it appears in.)
  8. \Documents and Settings\MatiasC\Escritorio\Practico 1 Soluciones\Sin Nombre1.cpp 47 C:\Documents and Settings\MatiasC\Escritorio\Practico 1 Soluciones\C [Error] cannot convert `int (*)[((unsigned int)((int)dim_plus))]' to `int (*)[2]' for argument `1' to `void jugadores(int (*)[2], int, int)'
  9. \Documents and Settings\MatiasC\Escritorio\Practico 1 Soluciones\Sin Nombre1.cpp 51 C:\Documents and Settings\MatiasC\Escritorio\Practico 1 Soluciones\C [Error] cannot convert `int (*)[((unsigned int)((int)dim_plus))]' to `int (*)[2]' for argument `1' to `void jugadores(int (*)[2], int, int)'
  10. C:\Documents and Settings\MatiasC\Escritorio\Practico 1 Soluciones\C Documents and Settings\MatiasC\Escritorio\Practico 1 Soluciones\Sin Nombre1.cpp: At global scope:
  11. \Documents and Settings\MatiasC\Escritorio\Practico 1 Soluciones\Sin Nombre1.cpp 61 C:\Documents and Settings\MatiasC\Escritorio\Practico 1 Soluciones\C [Error] variable-size type declared outside of any function
  12. \Documents and Settings\MatiasC\Escritorio\Practico 1 Soluciones\Sin Nombre1.cpp 61 C:\Documents and Settings\MatiasC\Escritorio\Practico 1 Soluciones\C [Error] variable-size type declared outside of any function
  13. In function `void dibujar_tablero(int (*)[2], int)':
  14. \Documents and Settings\MatiasC\Escritorio\Practico 1 Soluciones\Sin Nombre1.cpp 61 C:\Documents and Settings\MatiasC\Escritorio\Practico 1 Soluciones\C [Error] `void dibujar_tablero(int (*)[2], int)' used prior to declaration
  15. C:\Documents and Settings\MatiasC\Escritorio\Practico 1 Soluciones\C Documents and Settings\MatiasC\Escritorio\Practico 1 Soluciones\Sin Nombre1.cpp: At global scope:
  16. \Documents and Settings\MatiasC\Escritorio\Practico 1 Soluciones\Sin Nombre1.cpp 83 C:\Documents and Settings\MatiasC\Escritorio\Practico 1 Soluciones\C [Error] variable-size type declared outside of any function
  17. \Documents and Settings\MatiasC\Escritorio\Practico 1 Soluciones\Sin Nombre1.cpp 83 C:\Documents and Settings\MatiasC\Escritorio\Practico 1 Soluciones\C [Error] variable-size type declared outside of any function
  18. unrecognized option `-static-libstdc++'
  19.  

Ese error me sale cuando intento compilar el codigo que me colgaste abajo.
37  Programación / Programación C/C++ / Re: Juego 4 en linea. Ayuda!!! en: 5 Junio 2013, 13:54 pm
Muchas gracias leosansan, me ha sido de gran ayuda, pero cuando intento complilar el ultimo codigo me sale error cuando llamo al procedimiento imprimir_matriz; tampoco me dejan utilizar la el comando getchar  :-X

38  Programación / Programación C/C++ / Re: Juego 4 en linea. Ayuda!!! en: 4 Junio 2013, 22:25 pm
Hola gracias por las prontas respuestas,

si pongo tan solo printf("%c",matriz[k][n]); me deja toda la matriz en X.

Logro hacer la matriz inicial pero cuando quiero colocar un valor no me da, se me modifican varios.

Les agradezco sus respuestas!
39  Programación / Programación C/C++ / Juego 4 en linea. Ayuda!!! en: 3 Junio 2013, 16:47 pm
Buenas tardes soy nuevo en el foro y recien me estoy iniciando en el tema de la programacion, estoy intentando hacer el juego 4 en linea pero ando bastante trancado, elijo la dimension de mi tablero y muestro el mismo sin problemas pero cuando hago la primer jugada ya me muestra cualquier cosa.
Les dejo el codigo abajo para ver si me pueden ayudar.


Desde ya, muchas gracias.


Estoy compilando con DevC++


Codigo:

#include <stdio.h>
main()
{
   // Elejimos la dimension del tablero
   int n,k;
   printf("Ingrese la dimension del tablero de juego: ");
   scanf("%d",&n);
    char matriz[n][n];
    int i,j;

    // Mostramos el tablero inicial
    for (i=0;i<n;i++)
    {
       for (j=0;j<n;j++)
        {
           printf("%c ",matriz[j]='-');
          }
printf("\n");
     }
     printf("Haga su jugada: ");
     scanf("%d",&k);
     matriz[k][n]='X';
     printf("%c",matriz[k][n]+matriz[j]);
}
Páginas: 1 2 3 [4]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines