Ver Mensaje Individual
  #3 (permalink)  
Antiguo 27/05/2013, 17:48
Avatar de andre18agf
andre18agf
 
Fecha de Ingreso: mayo-2007
Mensajes: 13
Antigüedad: 17 años
Puntos: 0
Respuesta: No me corre juego tres rayas

Hola vosk, he hecho esto. Pero ahora la el procedimiento Jug me deberia intercambiar los jugadores y se queda en el jugador dos.

Código C:
Ver original
  1. #include <stdio.h>
  2. #define ROWS 3
  3. #define COLS 7
  4. #define WORLDSIZE (ROWS * COLS)
  5.  
  6. char matriz[WORLDSIZE];/*La matriz de tres en raya*/
  7. int  emp=1, pjug=1, repe1, coordx=0, coordy=0;
  8. char oc;
  9.  
  10. void valores()/*inicializador de valores*/
  11. {
  12.     emp=0; pjug=1;
  13.     int i, j;
  14.     for (i=0; i<=WORLDSIZE; i++)
  15.             matriz[i] =' ';
  16. }
  17. int getpos(int x, int y) {
  18.     return (COLS * (x - 1)) + (y - 1);
  19. }
  20. void casillas(int posicion)
  21. {
  22.     if (pjug == 1)
  23.         oc='X';
  24.     else
  25.         oc='O';
  26.     if (matriz[posicion] != ' '){
  27.         repe1=1; }
  28.     else{
  29.         matriz[posicion]=oc;
  30.         emp++;}
  31. }
  32.  
  33. void Jug(int Njug)
  34. {
  35.     int pos=0;
  36.     printf("Jugador %d - Introduce el numero: ",Njug);
  37.     scanf("\n%d,%d",&coordx, &coordy);
  38.     while (coordx>3 || coordy>7) {
  39.         printf("Opcion NO VALIDA, introduce una correcta: ");
  40.         scanf("\n%d,%d",&coordx, &coordy); }
  41.     pos = getpos(coordx, coordy);
  42.     casillas(pos);
  43.     if (repe1 == 1) {
  44.         printf("Casilla ya elegida! ");
  45.         repe1=0;
  46.         Jug(pjug);}
  47.             if(Njug){
  48.             pjug=2;}
  49.             else
  50.             pjug=1;
  51. }
  52.  
  53.  
  54. int cuadro(){
  55.  
  56. printf("\n\n 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | \n");
  57. printf("--------------------------------\n");
  58. printf(" 1 | %c | %c | %c | %c | %c | %c | %c |\n",matriz[0],matriz[1],matriz[2],matriz[3],matriz[4],matriz[5],matriz[6]);
  59. printf("--------------------------------\n");
  60. printf(" 2 | %c | %c | %c | %c | %c | %c | %c |\n",matriz[7],matriz[8],matriz[9],matriz[10],matriz[11],matriz[12],matriz[13]);
  61. printf("--------------------------------\n");
  62. printf(" 3 | %c | %c | %c | %c | %c | %c | %c |\n",matriz[14],matriz[15],matriz[16],matriz[17],matriz[18],matriz[19],matriz[20]);
  63. printf("--------------------------------\n");
  64.  
  65. return;
  66. }
  67. int main()
  68. {
  69.     int g=0;
  70. valores();
  71. while (WORLDSIZE)
  72. {
  73. cuadro();
  74. switch(pjug)
  75. {
  76. case 1 : Jug(pjug); break;
  77. case 2 : Jug(pjug); break;
  78. }
  79. }
  80. }