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

 

 


Tema destacado: Trabajando con las ramas de git (tercera parte)


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación C/C++ (Moderadores: Eternal Idol, Littlehorse, K-YreX)
| | |-+  juego slide puzzle
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: juego slide puzzle  (Leído 1,590 veces)
ereo

Desconectado Desconectado

Mensajes: 1


Ver Perfil
juego slide puzzle
« en: 21 Febrero 2016, 04:38 am »

tengo un problema, en general el juego funciona pero no puedo lograr que salga el mensaje de que ya gane   :-(

Código
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <conio.h>
  4. #include <windows.h>
  5. #include <time.h>
  6.  
  7. void gotoxy(short x, short y){
  8.    COORD pos = {x , y};
  9.    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);}
  10.  
  11. main()
  12. {
  13.    int r, x, y, j, vm, k, v,i;
  14.    int a[16], b[4][4],c[4][4];
  15.  
  16.    srand (time(NULL));
  17.     for (i=0; i<=14; i++) {
  18.        a[i] = rand()%(14+1);
  19.    }
  20.    r = 1;
  21.  
  22.    while (r == 1) {
  23.        r = 0;
  24.        for (i=0; i<=14; i++) {
  25.            if (a[i]==0)
  26.        a[i]++;
  27.            for (j=i+1; j<=14; j++)
  28. {
  29.  
  30.                if (a[i] == a[j] && a[i] !=15) {
  31.                    a[i] = a[i] +1;
  32.                    r = 1;
  33.  
  34.                }
  35.                if (a[i] == a[j] && a[i] ==15) {
  36.                    a[i] = a[i] -rand()%(14+1);
  37.                    r = 1; }
  38.            }}}
  39.  
  40.            j=0;
  41.    for (x=0; x<=3; x++) {
  42.     for(y=0; y<=3; y++)
  43. {b[x][y]=a[j];j++;
  44.         }}
  45.  x=3;
  46.  y=3;
  47.  fflush(stdin);
  48.  
  49. b[3][3]=0;
  50. c[0][0]=1;
  51.         c[0][1]=2;
  52.         c[0][2]=3;
  53.         c[0][3]=4;
  54.         c[1][0]=5;
  55.         c[1][1]=6;
  56.         c[1][2]=7;
  57.         c[1][3]=8;
  58.         c[2][0]=9;
  59.         c[2][1]=10;
  60.         c[2][2]=11;
  61.         c[2][3]=12;
  62.         c[3][0]=13;
  63.         c[3][1]=14;
  64.         c[3][2]=15;
  65.         c[3][3]=0;
  66.  
  67.  
  68. do{
  69.   ///////////////////IZQ////////////////////
  70. gotoxy(1,2);printf("%c",201);  
  71.        gotoxy(1,3);printf("%c",186);
  72.        gotoxy(1,4);printf("%c",204);
  73.        gotoxy(1,5);printf("%c",186);
  74.        gotoxy(1,6);printf("%c",186);
  75.        gotoxy(1,7);printf("%c",186);
  76.        gotoxy(1,8);printf("%c",204);
  77.        gotoxy(1,9);printf("%c",186);
  78.        gotoxy(1,10);printf("%c",200);
  79. ///////////////////DER////////////////////    
  80.        gotoxy(13,2);printf("%c",187);  
  81.        gotoxy(13,3);printf("%c",186);
  82.        gotoxy(13,4);printf("%c",185);
  83.        gotoxy(13,5);printf("%c",186);
  84.        gotoxy(13,6);printf("%c",186);
  85.        gotoxy(13,7);printf("%c",186);
  86.        gotoxy(13,8);printf("%c",185);
  87.        gotoxy(13,9);printf("%c",186);
  88.        gotoxy(13,10);printf("%c",188);      
  89. ///////////////////Arriba////////////////////
  90. gotoxy(2,2);printf("%c",205);    
  91.        gotoxy(3,2);printf("%c",205);  
  92.        gotoxy(4,2);printf("%c",203);
  93.        gotoxy(5,2);printf("%c",205);
  94.        gotoxy(6,2);printf("%c",205);
  95.        gotoxy(7,2);printf("%c",203);
  96.        gotoxy(8,2);printf("%c",205);  
  97. gotoxy(9,2);printf("%c",205);
  98. gotoxy(10,2);printf("%c",203);
  99. gotoxy(11,2);printf("%c",205);  
  100. gotoxy(12,2);printf("%c",205);    
  101. //////////////////ABAJO/////////////////////
  102. gotoxy(2,10);printf("%c",205);    
  103.        gotoxy(3,10);printf("%c",205);  
  104.        gotoxy(4,10);printf("%c",202);
  105.        gotoxy(5,10);printf("%c",205);
  106.        gotoxy(6,10);printf("%c",205);
  107.        gotoxy(7,10);printf("%c",202);
  108.        gotoxy(8,10);printf("%c",205);  
  109. gotoxy(9,10);printf("%c",205);
  110. gotoxy(10,10);printf("%c",202);
  111. gotoxy(11,10);printf("%c",205);  
  112. gotoxy(12,10);printf("%c",205);    
  113. /////////////////linea 1///////////////////  
  114.  
  115.        gotoxy(4,3);printf("%c",186);
  116.        gotoxy(4,4);printf("%c",206);
  117.        gotoxy(4,5);printf("%c",186);
  118.        gotoxy(4,6);printf("%c",206);
  119.        gotoxy(4,7);printf("%c",186);  
  120.        gotoxy(4,8);printf("%c",206);
  121.        gotoxy(4,9);printf("%c",186);
  122. /////////////////linea 2///////////////////  
  123.  
  124.        gotoxy(7,3);printf("%c",186);
  125.        gotoxy(7,4);printf("%c",206);
  126.        gotoxy(7,5);printf("%c",186);
  127.        gotoxy(7,6);printf("%c",206);
  128.        gotoxy(7,7);printf("%c",186);  
  129.        gotoxy(7,8);printf("%c",206);
  130.        gotoxy(7,9);printf("%c",186);
  131. /////////////////linea 3///////////////////  
  132.  
  133.        gotoxy(10,3);printf("%c",186);
  134.        gotoxy(10,4);printf("%c",206);
  135.        gotoxy(10,5);printf("%c",186);
  136.        gotoxy(10,6);printf("%c",206);
  137.        gotoxy(10,7);printf("%c",186);  
  138.        gotoxy(10,8);printf("%c",206);
  139.        gotoxy(10,9);printf("%c",186);        
  140. //////////////////ABAJO 1/////////////////////
  141. gotoxy(2,4);printf("%c",205);    
  142.        gotoxy(3,4);printf("%c",205);  
  143.        gotoxy(4,4);printf("%c",206);
  144.        gotoxy(5,4);printf("%c",205);
  145.        gotoxy(6,4);printf("%c",205);
  146.        gotoxy(7,4);printf("%c",206);
  147.        gotoxy(8,4);printf("%c",205);  
  148. gotoxy(9,4);printf("%c",205);
  149. gotoxy(10,4);printf("%c",206);
  150. gotoxy(11,4);printf("%c",205);  
  151. gotoxy(12,4);printf("%c",205);
  152. //////////////////ABAJO 1/////////////////////
  153. gotoxy(2,6);printf("%c",205);    
  154.        gotoxy(3,6);printf("%c",205);  
  155.        gotoxy(4,6);printf("%c",206);
  156.        gotoxy(5,6);printf("%c",205);
  157.        gotoxy(6,6);printf("%c",205);
  158.        gotoxy(7,6);printf("%c",206);
  159.        gotoxy(8,6);printf("%c",205);  
  160. gotoxy(9,6);printf("%c",205);
  161. gotoxy(10,6);printf("%c",206);
  162. gotoxy(11,6);printf("%c",205);  
  163. gotoxy(12,6);printf("%c",205);
  164. //////////////////ABAJO 1/////////////////////
  165. gotoxy(2,8);printf("%c",205);    
  166.        gotoxy(3,8);printf("%c",205);  
  167.        gotoxy(4,8);printf("%c",206);
  168.        gotoxy(5,8);printf("%c",205);
  169.        gotoxy(6,8);printf("%c",205);
  170.        gotoxy(7,8);printf("%c",206);
  171.        gotoxy(8,8);printf("%c",205);  
  172. gotoxy(9,8);printf("%c",205);
  173. gotoxy(10,8);printf("%c",206);
  174. gotoxy(11,8);printf("%c",205);  
  175. gotoxy(12,8);printf("%c",205);  
  176. ////////////////////////////////////////////
  177.   /////////////////////////
  178.  
  179.  gotoxy(2,3);printf("%d",b[0][0]);
  180.   gotoxy(5,3);printf("%d",b[0][1]);
  181.   gotoxy(8,3);printf("%d",b[0][2]);
  182.   gotoxy(11,3);printf("%d",b[0][3]);
  183.   gotoxy(2,5);printf("%d",b[1][0]);
  184.   gotoxy(5,5);printf("%d",b[1][1]);
  185.   gotoxy(8,5);printf("%d",b[1][2]);
  186.   gotoxy(11,5);printf("%d",b[1][3]);
  187.   gotoxy(2,7);printf("%d",b[2][0]);
  188.   gotoxy(5,7);printf("%d",b[2][1]);
  189.   gotoxy(8,7);printf("%d",b[2][2]);
  190.   gotoxy(11,7);printf("%d",b[2][3]);
  191.   gotoxy(2,9);printf("%d",b[3][0]);
  192.   gotoxy(5,9);printf("%d",b[3][1]);
  193.   gotoxy(8,9);printf("%d",b[3][2]);
  194.   gotoxy(11,9);printf("%d",b[3][3]);
  195.  
  196.   //////////////////////////////////////
  197.  
  198.  
  199.    vm=getch();
  200.    system("cls");
  201.  
  202.    switch(vm)
  203.    {
  204.     case 80: //FLECHA DERECHA
  205.     if(x <= 2){
  206.  
  207. v=b[x+1][y];
  208. b[x][y]=v;
  209. b[x+1][y]=0;
  210. x++;
  211. }    
  212.  
  213.     break;
  214.     case 72: //FLECHA IZQUIERDA
  215.     if(x>0)
  216. {
  217.  
  218. v=b[x-1][y];
  219. b[x-1][y]=0;
  220. b[x][y]=v;
  221.    x--;
  222. }
  223.  
  224.     break;
  225.     case 77:   //FLECHA ABAJO
  226.     if(y <= 2)
  227.     {
  228.     v=b[x][y+1];
  229.     b[x][y+1]=0;
  230.     b[x][y]=v;
  231.     y++;
  232. }
  233.  
  234.   break;
  235.     case 75:    //FLECHA ARRIBA
  236.     if(y > 0)
  237.     {
  238.     v=b[x][y-1];
  239.     b[x][y-1]=0;
  240.     b[x][y]=v;
  241.     y--;
  242. }
  243.  
  244.     break;
  245.  
  246.   } }while(vm!=13);
  247.  
  248. }


En línea

Eternal Idol
Kernel coder
Moderador
***
Desconectado Desconectado

Mensajes: 5.937


Israel nunca torturó niños, ni lo volverá a hacer.


Ver Perfil WWW
Re: juego slide puzzle
« Respuesta #1 en: 21 Febrero 2016, 11:30 am »

¿Y donde esta el mensaje ese?  :huh:

Hagas lo que hagas el programa termina cuando le das a ENTER (13, mira el codigo con atencion), no lo entiendo del todo pero me imagino que tenes que agregar el codigo para que antes de terminar compruebe si se soluciono el problema y en todo caso salga si ganaste o perdiste ...


En línea

La economía nunca ha sido libre: o la controla el Estado en beneficio del Pueblo o lo hacen los grandes consorcios en perjuicio de éste.
Juan Domingo Perón
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Puzzle en dev c++
Programación C/C++
brikejedek 2 10,100 Último mensaje 22 Noviembre 2010, 00:16 am
por brikejedek
Puzzle 8 en c
Programación C/C++
twins 0 2,853 Último mensaje 21 Junio 2012, 23:27 pm
por twins
Crear una puzzle en c sharp
Programación C/C++
thinlizzy 1 3,766 Último mensaje 25 Agosto 2012, 05:40 am
por durasno
Puzzle 8
Programación C/C++
Luis100710 2 2,450 Último mensaje 16 Abril 2014, 00:29 am
por erickgracia
Puzzle 8 en C
Programación C/C++
eduardo1012 6 3,446 Último mensaje 26 Abril 2016, 05:26 am
por eduardo1012
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines