Código
#include <stdio.h> #include <stdlib.h> #include <conio.h> #include <windows.h> #include <time.h> void gotoxy(short x, short y){ COORD pos = {x , y}; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);} main() { int r, x, y, j, vm, k, v,i; int a[16], b[4][4],c[4][4]; for (i=0; i<=14; i++) { } r = 1; while (r == 1) { r = 0; for (i=0; i<=14; i++) { if (a[i]==0) a[i]++; for (j=i+1; j<=14; j++) { if (a[i] == a[j] && a[i] !=15) { a[i] = a[i] +1; r = 1; } if (a[i] == a[j] && a[i] ==15) { r = 1; } }}} j=0; for (x=0; x<=3; x++) { for(y=0; y<=3; y++) {b[x][y]=a[j];j++; }} x=3; y=3; b[3][3]=0; c[0][0]=1; c[0][1]=2; c[0][2]=3; c[0][3]=4; c[1][0]=5; c[1][1]=6; c[1][2]=7; c[1][3]=8; c[2][0]=9; c[2][1]=10; c[2][2]=11; c[2][3]=12; c[3][0]=13; c[3][1]=14; c[3][2]=15; c[3][3]=0; do{ ///////////////////IZQ//////////////////// gotoxy(1,2);printf("%c",201); gotoxy(1,3);printf("%c",186); gotoxy(1,4);printf("%c",204); gotoxy(1,5);printf("%c",186); gotoxy(1,6);printf("%c",186); gotoxy(1,7);printf("%c",186); gotoxy(1,8);printf("%c",204); gotoxy(1,9);printf("%c",186); gotoxy(1,10);printf("%c",200); ///////////////////DER//////////////////// gotoxy(13,2);printf("%c",187); gotoxy(13,3);printf("%c",186); gotoxy(13,4);printf("%c",185); gotoxy(13,5);printf("%c",186); gotoxy(13,6);printf("%c",186); gotoxy(13,7);printf("%c",186); gotoxy(13,8);printf("%c",185); gotoxy(13,9);printf("%c",186); gotoxy(13,10);printf("%c",188); ///////////////////Arriba//////////////////// gotoxy(2,2);printf("%c",205); gotoxy(3,2);printf("%c",205); gotoxy(4,2);printf("%c",203); gotoxy(5,2);printf("%c",205); gotoxy(6,2);printf("%c",205); gotoxy(7,2);printf("%c",203); gotoxy(8,2);printf("%c",205); gotoxy(9,2);printf("%c",205); gotoxy(10,2);printf("%c",203); gotoxy(11,2);printf("%c",205); gotoxy(12,2);printf("%c",205); //////////////////ABAJO///////////////////// gotoxy(2,10);printf("%c",205); gotoxy(3,10);printf("%c",205); gotoxy(4,10);printf("%c",202); gotoxy(5,10);printf("%c",205); gotoxy(6,10);printf("%c",205); gotoxy(7,10);printf("%c",202); gotoxy(8,10);printf("%c",205); gotoxy(9,10);printf("%c",205); gotoxy(10,10);printf("%c",202); gotoxy(11,10);printf("%c",205); gotoxy(12,10);printf("%c",205); /////////////////linea 1/////////////////// gotoxy(4,3);printf("%c",186); gotoxy(4,4);printf("%c",206); gotoxy(4,5);printf("%c",186); gotoxy(4,6);printf("%c",206); gotoxy(4,7);printf("%c",186); gotoxy(4,8);printf("%c",206); gotoxy(4,9);printf("%c",186); /////////////////linea 2/////////////////// gotoxy(7,3);printf("%c",186); gotoxy(7,4);printf("%c",206); gotoxy(7,5);printf("%c",186); gotoxy(7,6);printf("%c",206); gotoxy(7,7);printf("%c",186); gotoxy(7,8);printf("%c",206); gotoxy(7,9);printf("%c",186); /////////////////linea 3/////////////////// gotoxy(10,3);printf("%c",186); gotoxy(10,4);printf("%c",206); gotoxy(10,5);printf("%c",186); gotoxy(10,6);printf("%c",206); gotoxy(10,7);printf("%c",186); gotoxy(10,8);printf("%c",206); gotoxy(10,9);printf("%c",186); //////////////////ABAJO 1///////////////////// gotoxy(2,4);printf("%c",205); gotoxy(3,4);printf("%c",205); gotoxy(4,4);printf("%c",206); gotoxy(5,4);printf("%c",205); gotoxy(6,4);printf("%c",205); gotoxy(7,4);printf("%c",206); gotoxy(8,4);printf("%c",205); gotoxy(9,4);printf("%c",205); gotoxy(10,4);printf("%c",206); gotoxy(11,4);printf("%c",205); gotoxy(12,4);printf("%c",205); //////////////////ABAJO 1///////////////////// gotoxy(2,6);printf("%c",205); gotoxy(3,6);printf("%c",205); gotoxy(4,6);printf("%c",206); gotoxy(5,6);printf("%c",205); gotoxy(6,6);printf("%c",205); gotoxy(7,6);printf("%c",206); gotoxy(8,6);printf("%c",205); gotoxy(9,6);printf("%c",205); gotoxy(10,6);printf("%c",206); gotoxy(11,6);printf("%c",205); gotoxy(12,6);printf("%c",205); //////////////////ABAJO 1///////////////////// gotoxy(2,8);printf("%c",205); gotoxy(3,8);printf("%c",205); gotoxy(4,8);printf("%c",206); gotoxy(5,8);printf("%c",205); gotoxy(6,8);printf("%c",205); gotoxy(7,8);printf("%c",206); gotoxy(8,8);printf("%c",205); gotoxy(9,8);printf("%c",205); gotoxy(10,8);printf("%c",206); gotoxy(11,8);printf("%c",205); gotoxy(12,8);printf("%c",205); //////////////////////////////////////////// ///////////////////////// gotoxy(2,3);printf("%d",b[0][0]); gotoxy(5,3);printf("%d",b[0][1]); gotoxy(8,3);printf("%d",b[0][2]); gotoxy(11,3);printf("%d",b[0][3]); gotoxy(2,5);printf("%d",b[1][0]); gotoxy(5,5);printf("%d",b[1][1]); gotoxy(8,5);printf("%d",b[1][2]); gotoxy(11,5);printf("%d",b[1][3]); gotoxy(2,7);printf("%d",b[2][0]); gotoxy(5,7);printf("%d",b[2][1]); gotoxy(8,7);printf("%d",b[2][2]); gotoxy(11,7);printf("%d",b[2][3]); gotoxy(2,9);printf("%d",b[3][0]); gotoxy(5,9);printf("%d",b[3][1]); gotoxy(8,9);printf("%d",b[3][2]); gotoxy(11,9);printf("%d",b[3][3]); ////////////////////////////////////// switch(vm) { case 80: //FLECHA DERECHA if(x <= 2){ v=b[x+1][y]; b[x][y]=v; b[x+1][y]=0; x++; } break; case 72: //FLECHA IZQUIERDA if(x>0) { v=b[x-1][y]; b[x-1][y]=0; b[x][y]=v; x--; } break; case 77: //FLECHA ABAJO if(y <= 2) { v=b[x][y+1]; b[x][y+1]=0; b[x][y]=v; y++; } break; case 75: //FLECHA ARRIBA if(y > 0) { v=b[x][y-1]; b[x][y-1]=0; b[x][y]=v; y--; } break; } }while(vm!=13); }