Advertisement
Guest User

testris error404

a guest
Jun 17th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 10.33 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <conio.h>
  5. #include <windows.h>
  6.  
  7.  
  8.  
  9. #define COLT 12
  10. #define FILAT 24
  11.  
  12.  
  13. char tablero[FILAT][COLT] = {0};
  14.  
  15. typedef struct
  16. {
  17.     int activa;                   /// activa 1 no activa 0 en tablero
  18.     int color;                   /// Comming Soon
  19.     int limite;                 /// Maxima extension de una ficha horizontal y vertical
  20.     char pieza[4][4][4];       /// Matriz 3D ROTACION-FILA-COLUMNA
  21. } Pieza;
  22.  
  23. ///Carga las matrices Almacenes en las struc de las fichas
  24. void cargarPiezasenFichas(int rot,int fil,int col,char ficha[rot][fil][col],char almacen[rot][fil][col]);
  25. void cargarPiezaAJugar(Pieza fija, Pieza enJuego);
  26. void mostrarPiezaMatri1 (int rotacion,int fila, int colum, char matri1[rotacion][fila][colum]);
  27. int rotacionPieza(Pieza piezaN, int rot);
  28. void mostrarTablero (char tablero[FILAT][COLT]);
  29. int pasaFichaToTablero (int rotacion,int i, char tablero[FILAT][COLT], Pieza enJuego);
  30. void limpiaTablero (char tablero[FILAT][COLT]);
  31.  
  32. int main()
  33. {
  34.     SetConsoleTitle("Tetris ERROR 404 v0.0 UTN MDP [JUN-2019]");
  35.  
  36.  
  37.     int rotacion=0;
  38.     char controlROT=getch();
  39.     //char controlPIEZ='o';
  40.     int selecPieza=0;
  41.     int ultimaFila=0;
  42.  
  43.     //char ctrlMov=getch();
  44.     int movAbajo=0;
  45.     int movIzquier=0;
  46.     int Piezas[7];
  47.  
  48.     mostrarTablero(tablero);
  49.  
  50.     Pieza aJugar;
  51.  
  52.  
  53.     Pieza fichaL,fichaLI,fichaS,fichaSI,fichaT,fichaC,fichaP;
  54.     ///ficha L
  55.     fichaL.activa =1;
  56.     fichaL.limite =3;
  57.     fichaL.color =1;
  58.     ///ficha L Invertida
  59.     fichaLI.activa =1;
  60.     fichaLI.limite =3;
  61.     fichaLI.color =2;
  62.     ///ficha S
  63.     fichaS.activa =1;
  64.     fichaS.limite =3;
  65.     fichaS.color =3;
  66.     ///ficha S Invertida
  67.     fichaSI.activa =1;
  68.     fichaSI.limite =3;
  69.     fichaSI.color =4;
  70.     ///ficha T
  71.     fichaT.activa=1;
  72.     fichaT.limite=3;
  73.     fichaT.color=5;
  74.     ///ficha Cubo
  75.     fichaC.activa =1;
  76.     fichaC.limite =2;
  77.     fichaC.color =6;
  78.     ///ficha Palo
  79.     fichaP.activa =1;
  80.     fichaP.limite =4;
  81.     fichaP.color =7;
  82.  
  83.     ///Almacenes de fichas para introducir en la estructura pieza.ficha
  84.     char almacenELE[4][4][4]=
  85.     {
  86.         {
  87.             {'1','0','0','0'},
  88.             {'1','0','0','0'},
  89.             {'1','1','0','0'},
  90.             {'0','0','0','0'}
  91.         },{
  92.             {'1','1','1','0'},
  93.             {'1','0','0','0'},
  94.             {'0','0','0','0'},
  95.             {'0','0','0','0'}
  96.         },{
  97.             {'1','1','0','0'},
  98.             {'0','1','0','0'},
  99.             {'0','1','0','0'},
  100.             {'0','0','0','0'}
  101.         },{
  102.             {'0','0','1','0'},
  103.             {'1','1','1','0'},
  104.             {'0','0','0','0'},
  105.             {'0','0','0','0'}
  106.         }
  107.     };
  108.     char almacenELEI[4][4][4]=
  109.     {
  110.         {
  111.             {'0','1','0','0'},
  112.             {'0','1','0','0'},
  113.             {'1','1','0','0'},
  114.             {'0','0','0','0'}
  115.         },{
  116.             {'1','0','0','0'},
  117.             {'1','1','1','0'},
  118.             {'0','0','0','0'},
  119.             {'0','0','0','0'}
  120.         },{
  121.             {'1','1','0','0'},
  122.             {'1','0','0','0'},
  123.             {'1','0','0','0'},
  124.             {'0','0','0','0'}
  125.         },{
  126.             {'1','1','1','0'},
  127.             {'0','0','1','0'},
  128.             {'0','0','0','0'},
  129.             {'0','0','0','0'}
  130.         }
  131.     };
  132.     char almacenESE[4][4][4]=
  133.     {
  134.         {
  135.             {'0','1','1','0'},
  136.             {'1','1','0','0'},
  137.             {'0','0','0','0'},
  138.             {'0','0','0','0'}
  139.         },{
  140.             {'1','0','0','0'},
  141.             {'1','1','0','0'},
  142.             {'0','1','0','0'},
  143.             {'0','0','0','0'}
  144.         },{
  145.             {'0','1','1','0'},
  146.             {'1','1','0','0'},
  147.             {'0','0','0','0'},
  148.             {'0','0','0','0'}
  149.         },{
  150.             {'1','0','0','0'},
  151.             {'1','1','0','0'},
  152.             {'0','1','0','0'},
  153.             {'0','0','0','0'}
  154.         }
  155.     };
  156.     char almacenESEI[4][4][4]=
  157.     {
  158.         {
  159.             {'1','1','0','0'},
  160.             {'0','1','1','0'},
  161.             {'0','0','0','0'},
  162.             {'0','0','0','0'}
  163.         },{
  164.             {'0','1','0','0'},
  165.             {'1','1','0','0'},
  166.             {'1','0','0','0'},
  167.             {'0','0','0','0'}
  168.         },{
  169.             {'1','1','0','0'},
  170.             {'0','1','1','0'},
  171.             {'0','0','0','0'},
  172.             {'0','0','0','0'}
  173.         },{
  174.             {'0','1','0','0'},
  175.             {'1','1','0','0'},
  176.             {'1','0','0','0'},
  177.             {'0','0','0','0'}
  178.         }
  179.     };
  180.     char almacenLAT[4][4][4]=
  181.     {
  182.         {
  183.             {'0','1','0','0'},
  184.             {'1','1','1','0'},
  185.             {'0','0','0','0'},
  186.             {'0','0','0','0'}
  187.         },{
  188.             {'0','1','0','0'},
  189.             {'0','1','1','0'},
  190.             {'0','1','0','0'},
  191.             {'0','0','0','0'}
  192.         },{
  193.             {'0','0','0','0'},
  194.             {'1','1','1','0'},
  195.             {'0','1','0','0'},
  196.             {'0','0','0','0'}
  197.         },{
  198.             {'0','1','0','0'},
  199.             {'1','1','0','0'},
  200.             {'0','1','0','0'},
  201.             {'0','0','0','0'}
  202.         }
  203.     };
  204.     char almacenCUBO[4][4][4]=
  205.     {
  206.         {
  207.             {'1','1','0','0'},
  208.             {'1','1','0','0'},
  209.             {'0','0','0','0'},
  210.             {'0','0','0','0'}
  211.         },{
  212.             {'1','1','0','0'},
  213.             {'1','1','0','0'},
  214.             {'0','0','0','0'},
  215.             {'0','0','0','0'}
  216.         },{
  217.             {'1','1','0','0'},
  218.             {'1','1','0','0'},
  219.             {'0','0','0','0'},
  220.             {'0','0','0','0'}
  221.         },{
  222.             {'1','1','0','0'},
  223.             {'1','1','0','0'},
  224.             {'0','0','0','0'},
  225.             {'0','0','0','0'}
  226.         }
  227.     };
  228.     char almacenPALO[4][4][4]=
  229.     {
  230.         {
  231.             {'0','1','0','0'},
  232.             {'0','1','0','0'},
  233.             {'0','1','0','0'},
  234.             {'0','1','0','0'}
  235.         },{
  236.             {'0','0','0','0'},
  237.             {'1','1','1','1'},
  238.             {'0','0','0','0'},
  239.             {'0','0','0','0'}
  240.         },{
  241.             {'0','1','0','0'},
  242.             {'0','1','0','0'},
  243.             {'0','1','0','0'},
  244.             {'0','1','0','0'}
  245.         },{
  246.             {'0','0','0','0'},
  247.             {'1','1','1','1'},
  248.             {'0','0','0','0'},
  249.             {'0','0','0','0'}
  250.         }
  251.     };
  252.     ///carga de las matrices en las estruc
  253.     cargarPiezasenFichas(4,4,4,fichaL.pieza,almacenELE);
  254.     cargarPiezasenFichas(4,4,4,fichaLI.pieza,almacenELEI);
  255.     cargarPiezasenFichas(4,4,4,fichaS.pieza,almacenESE);
  256.     cargarPiezasenFichas(4,4,4,fichaSI.pieza,almacenESEI);
  257.     cargarPiezasenFichas(4,4,4,fichaT.pieza,almacenLAT);
  258.     cargarPiezasenFichas(4,4,4,fichaC.pieza,almacenCUBO);
  259.     cargarPiezasenFichas(4,4,4,fichaP.pieza,almacenPALO);
  260.  
  261.  
  262.     do
  263.     {
  264.         fflush(stdin);
  265.         printf("%c ",controlROT=getch());
  266.         if (controlROT=='r')
  267.         {
  268.             rotacion=rotacionPieza(fichaT,rotacion);
  269.             movIzquier=pasaFichaToTablero(rotacion,movAbajo,tablero,fichaT);
  270.             system("cls");
  271.             mostrarTablero(tablero);
  272.             limpiaTablero(tablero);
  273.         }
  274.         else if (controlROT=='f')
  275.         {
  276.             ultimaFila=pasaFichaToTablero(rotacion,movAbajo,tablero,fichaT);
  277.             //printf("%d\n",ultimaFila);
  278.             system("cls");
  279.             mostrarTablero(tablero);
  280.             movAbajo++;
  281.             limpiaTablero(tablero);
  282.         }
  283.     }
  284.     while(ultimaFila!=24);
  285.  
  286.  
  287.  
  288.     return 0;
  289. }
  290.  
  291. void mostrarPiezaMatri1 (int rotacion,int fila, int colum, char matri1[rotacion][fila][colum])
  292. {
  293.     int i;
  294.     int j;
  295.  
  296.     for(i=0; i<fila; i++)
  297.     {
  298.         for(j=0; j<colum; j++)
  299.         {
  300.             if(matri1[rotacion][i][j]!='0')
  301.                 //printf("%c",matri1[rotacion][i][j]);
  302.                 printf("X");
  303.             else
  304.                 printf(" ");
  305.         }
  306.         printf("\n");
  307.     }
  308. }
  309.  
  310. void cargarPiezasenFichas(int rot,int fil,int col,char ficha[rot][fil][col],char almacen[rot][fil][col])
  311. {
  312.     int i=0;
  313.     int j=0;
  314.     int k=0;
  315.  
  316.     for(i=0; i<rot; i++)
  317.     {
  318.         for(j=0; j<fil; j++)
  319.         {
  320.             for(k=0; k<col; k++)
  321.             {
  322.                 ficha[i][j][k]=almacen[i][j][k];
  323.             }
  324.         }
  325.     }
  326.  
  327. }
  328.  
  329. int rotacionPieza(Pieza piezaN, int rot)
  330. {
  331.     rot++;
  332.     if(rot==4)
  333.         rot=0;
  334.     piezaN.pieza[rot];
  335.     return rot;
  336. }
  337.  
  338. void cargarPiezaAJugar(Pieza fija, Pieza enJuego)
  339. {
  340.     int i,j,k;
  341.     enJuego.limite=fija.limite;
  342.     enJuego.color=fija.color;
  343.  
  344.     for(i=0; i<4; i++)
  345.     {
  346.         for(j=0; j<4; j++)
  347.         {
  348.             for(k=0; k<4; k++)
  349.             {
  350.                 enJuego.pieza[i][j][k]= fija.pieza[i][j][k];
  351.             }
  352.         }
  353.     }
  354. }
  355.  
  356. void mostrarTablero (char tablero[FILAT][COLT]) ///Imprime el tablero y analiza como dibujarlo.
  357. {
  358.     int i,j;
  359.     for (i=0; i<FILAT; i++)
  360.     {
  361.         for(j=0; j<COLT; j++)
  362.         {
  363.             /*if(tablero[i][j]=='1')
  364.  
  365.                 printf("X");
  366.             else
  367.                 printf(".");*/
  368.             printf(" %c", (tablero[i][j]=='1')? 'X' : 250);
  369.         }
  370.         printf("\n");
  371.     }
  372. }
  373. ///**** PASA LA FICHA CORRECTAMENTE  ***//////
  374. int pasaFichaToTablero (int rotacion,int i, char tablero[FILAT][COLT], Pieza enJuego)
  375. {
  376.     int posicion=0;
  377.     int j=3;   ///tienen que ser iguales
  378.     int c2=0;
  379.     int c1=0;
  380.     while ((i<FILAT)&&(c1<4))
  381.     {
  382.         while ((j<COLT)&&(c2<4))
  383.         {
  384.             tablero[i][j] = enJuego.pieza[rotacion][c1][c2];
  385.             c2++;
  386.             j++;
  387.         }
  388.  
  389.         i++;
  390.         c2=0;
  391.         j=3;    ///tiene que ser iguales
  392.         c1++;
  393.  
  394.     }
  395.     /*  for (i=0; i<fila; i++)
  396.       {
  397.           if (c1<5)
  398.           {
  399.               for(j=1; j<colum; j++)
  400.               {
  401.                   if (c2<5)
  402.                   {
  403.                       tablero[i][j] = enJuego.pieza[c1][c2];
  404.                       c2++;
  405.                   }
  406.               }
  407.  
  408.  
  409.               c2=0;
  410.               c1++;
  411.           }
  412.           // else i=fila;*/
  413.  
  414.     posicion++;
  415.     return posicion;
  416. }
  417.  
  418. void limpiaTablero (char tablero[FILAT][COLT])  ///Limpia el tablero del residuo del movimiento anterior.
  419. {
  420.     int i,j;
  421.     for(i=0; i<FILAT; i++)
  422.     {
  423.         for (j=0; j<COLT; j++)
  424.         {
  425.             tablero[i][j]=0;
  426.         }
  427.     }
  428. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement