Advertisement
jacknpoe

DROPS 1 (tetris)

Oct 19th, 2013
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 16.15 KB | None | 0 0
  1. // SÓ COMPILARÁ EM COMPILADORES BORLAND ANTIGOS
  2.  
  3. #include <stdarg.h>
  4. #include <stdio.h>
  5. #include <conio.h>
  6. #include <graphics.h>
  7. #include <iostream.h>
  8. #include <io.h>
  9. #include <fcntl.h>
  10. #include <stdlib.h>
  11. #include <process.h>
  12. #include <time.h>
  13. #include <dos.h>
  14.  
  15. int  gprintf( int *xloc, int *yloc, char *fmt, ... );
  16. int  bateu(int alt, int hor, int pec, int rot);
  17. void cola(int alt, int hor, int pec, int rot);
  18. void final(void);
  19. void gameover(void);
  20. void poe(int alt1, int alt2, float hor, int pec, int rot);
  21. int  possivel(int alt1, int alt2, int hor, int pec, int rot);
  22. void score(void);
  23. void tir1(int alt1, int alt2, int hor, int pec, int rot);
  24. void tire(int alt1, int alt2, int hor, int pec, int rot);
  25. /* void troque(void); */
  26. void cores(int monitor);
  27. int  inicializa();
  28. void inicializa2(void);
  29. int  jogo(void);
  30. void quadrado(void);
  31. void iround(void);
  32. int  desce(void);
  33. int teclas(int alt1, int alt2, int pec);
  34.  
  35.  
  36.  
  37. int      cor[9], malha[12][21], round, linhas, prox=1, peca1, cai, horiz, rotacao;
  38. long int pontos, record=20000;
  39. char     drops[100];
  40. char     faixa[14804];
  41. char     dentro[8] = {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
  42. int      ic[7][4][4][4]= {{{{0,1,0,0},
  43.                 {0,1,1,0},
  44.                 {0,0,1,0},
  45.                 {0,0,0,0}},
  46.  
  47.                {{0,1,1,0},
  48.                 {1,1,0,0},
  49.                 {0,0,0,0},
  50.                 {0,0,0,0}},
  51.  
  52.                {{0,1,0,0},
  53.                 {0,1,1,0},
  54.                 {0,0,1,0},
  55.                 {0,0,0,0}},
  56.  
  57.                {{0,0,1,1},
  58.                 {0,1,1,0},
  59.                 {0,0,0,0},
  60.                 {0,0,0,0}}},
  61.  
  62.  
  63.               {{{0,0,1,0},
  64.                 {0,1,1,0},
  65.                 {0,1,0,0},
  66.                 {0,0,0,0}},
  67.  
  68.                {{0,1,1,0},
  69.                 {0,0,1,1},
  70.                 {0,0,0,0},
  71.                 {0,0,0,0}},
  72.  
  73.                {{0,0,1,0},
  74.                 {0,1,1,0},
  75.                 {0,1,0,0},
  76.                 {0,0,0,0}},
  77.  
  78.                {{1,1,0,0},
  79.                 {0,1,1,0},
  80.                 {0,0,0,0},
  81.                 {0,0,0,0}}},
  82.  
  83.  
  84.               {{{1,1,1,0},
  85.                 {1,0,0,0},
  86.                 {0,0,0,0},
  87.                 {0,0,0,0}},
  88.  
  89.                {{0,1,1,0},
  90.                 {0,0,1,0},
  91.                 {0,0,1,0},
  92.                 {0,0,0,0}},
  93.  
  94.                {{0,0,0,1},
  95.                 {0,1,1,1},
  96.                 {0,0,0,0},
  97.                 {0,0,0,0}},
  98.  
  99.                {{0,1,0,0},
  100.                 {0,1,0,0},
  101.                 {0,1,1,0},
  102.                 {0,0,0,0}}},
  103.  
  104.  
  105.               {{{0,0,1,0},
  106.                 {0,0,1,0},
  107.                 {0,1,1,0},
  108.                 {0,0,0,0}},
  109.  
  110.                {{1,0,0,0},
  111.                 {1,1,1,0},
  112.                 {0,0,0,0},
  113.                 {0,0,0,0}},
  114.  
  115.                {{0,1,1,0},
  116.                 {0,1,0,0},
  117.                 {0,1,0,0},
  118.                 {0,0,0,0}},
  119.  
  120.                {{0,1,1,1},
  121.                 {0,0,0,1},
  122.                 {0,0,0,0},
  123.                 {0,0,0,0}}},
  124.  
  125.  
  126.               {{{0,0,0,0},
  127.                 {0,1,1,0},
  128.                 {0,1,1,0},
  129.                 {0,0,0,0}},
  130.  
  131.                {{0,0,0,0},
  132.                 {0,1,1,0},
  133.                 {0,1,1,0},
  134.                 {0,0,0,0}},
  135.  
  136.                {{0,0,0,0},
  137.                 {0,1,1,0},
  138.                 {0,1,1,0},
  139.                 {0,0,0,0}},
  140.  
  141.                {{0,0,0,0},
  142.                 {0,1,1,0},
  143.                 {0,1,1,0},
  144.                 {0,0,0,0}}},
  145.  
  146.  
  147.               {{{0,0,0,0},
  148.                 {1,1,1,1},
  149.                 {0,0,0,0},
  150.                 {0,0,0,0}},
  151.  
  152.                {{0,1,0,0},
  153.                 {0,1,0,0},
  154.                 {0,1,0,0},
  155.                 {0,1,0,0}},
  156.  
  157.                {{0,0,0,0},
  158.                 {1,1,1,1},
  159.                 {0,0,0,0},
  160.                 {0,0,0,0}},
  161.  
  162.                {{0,0,1,0},
  163.                 {0,0,1,0},
  164.                 {0,0,1,0},
  165.                 {0,0,1,0}}},
  166.  
  167.  
  168.               {{{0,0,1,0},
  169.                 {0,1,1,0},
  170.                 {0,0,1,0},
  171.                 {0,0,0,0}},
  172.  
  173.                {{0,1,0,0},
  174.                 {1,1,1,0},
  175.                 {0,0,0,0},
  176.                 {0,0,0,0}},
  177.  
  178.                {{0,1,0,0},
  179.                 {0,1,1,0},
  180.                 {0,1,0,0},
  181.                 {0,0,0,0}},
  182.  
  183.                {{0,1,1,1},
  184.                 {0,0,1,0},
  185.                 {0,0,0,0},
  186.                 {0,0,0,0}}}};
  187.  
  188.  
  189.  
  190. main()      // versão 2013
  191. {
  192.     unsigned int temp=0;
  193.     if (inicializa()==1) return 1;
  194.     randomize();
  195.     quadrado();
  196.     while( 1)
  197.     {
  198.         inicializa2();
  199.         while(kbhit()) getch();
  200.         temp=getch();
  201.         if (temp==27) break;
  202.         temp=jogo();
  203.         if (temp==1) final();
  204.         if (temp==0) gameover();
  205.     }
  206.     closegraph();
  207.     return 0;
  208. }
  209.  
  210. /* Funcao inicializa ************************************** */
  211.  
  212. int inicializa()
  213. {
  214.     int monitor = DETECT, cartao;
  215.     initgraph(&monitor,&cartao,"");
  216.     if (!((monitor<5 && monitor>0) || (monitor>7 && monitor<10)))
  217.     {
  218.         closegraph();
  219.         printf("Sua placa n„o pode exibir a resolu‡„o exigida pelo programa.\n");
  220.         printf("DROPS (R) s¢ roda em placas CGA, EGA, VGA, ATT400 e MCGA.\n");
  221.         return 1;
  222.     }
  223.     if (monitor == 1) setgraphmode(CGAHI);
  224.     if (monitor == 2) setgraphmode(MCGAMED);
  225.     if (monitor == 3) setgraphmode(EGALO);
  226.     if (monitor == 4) setgraphmode(EGA64LO);
  227.     if (monitor == 8) setgraphmode(ATT400MED);
  228.     if (monitor == 9) setgraphmode(VGALO);
  229.     cores(monitor);
  230.     return 0;
  231. }
  232.  
  233.  
  234. /* Funcao cores ******************************************* */
  235.  
  236. void cores(int monitor)
  237. {
  238.     if (monitor == 4 || monitor == 3 || monitor == 9)
  239.     {
  240.         printf("Monocrom†tico ou Colorido?");
  241.         char collor;
  242.         while(!kbhit());
  243.         collor = getche();
  244.         if (collor == 'M' || collor == 'm')
  245.         {
  246.             cor[0] = 8;
  247.             cor[1] = 2;
  248.             cor[2] = 2;
  249.             cor[3] = 2;
  250.             cor[4] =15;
  251.             cor[5] = 8;
  252.             cor[6] = 0;
  253.             cor[7] = 2;
  254.             cor[8] =15;
  255.         }
  256.         else
  257.         {
  258.             cor[0] = 1;
  259.             cor[1] = 3;
  260.             cor[2] = 2;
  261.             cor[3] = 9;
  262.             cor[4] = 3;
  263.             cor[5] = 4;
  264.             cor[6] = 0;
  265.             cor[7] =14;
  266.             cor[8] =15;
  267.         }
  268.     }
  269.     else
  270.     {
  271.         cor[0] = 1;
  272.         cor[1] = 0;
  273.         cor[2] = 1;
  274.         cor[3] = 1;
  275.         cor[4] = 1;
  276.         cor[5] = 1;
  277.         cor[6] = 0;
  278.         cor[7] = 1;
  279.         cor[8] = 1;
  280.     }
  281. }
  282.  
  283.  
  284. /* Funcao inicializa2 ************************************* */
  285.  
  286. void inicializa2(void)
  287. {
  288.     int x;
  289.     clearviewport();
  290.     settextstyle(GOTHIC_FONT, HORIZ_DIR, 15);
  291.     setcolor(cor[0]);
  292.     settextjustify(CENTER_TEXT,BOTTOM_TEXT);
  293.     for(x=-3;x<2;x++)
  294.     {
  295.         outtextxy(getmaxx()/2+x-2,89,"DROPS");
  296.     }
  297.     setcolor(cor[3]);
  298.     outtextxy(getmaxx()/2,90,"DROPS");
  299.     settextstyle(SMALL_FONT, HORIZ_DIR, 9);
  300.     setcolor(cor[8]);
  301.     outtextxy(getmaxx()/2, 199,"DROPS versao 2.0 - ZiCauSoft 1993");
  302.     outtextxy(getmaxx()/2, 200,"           ~                      ");
  303.     settextstyle(DEFAULT_FONT, HORIZ_DIR, 1);
  304.     outtextxy(getmaxx()/2, 140,"Pressione Qualquer Tecla");
  305.     setcolor(cor[0]);
  306.     rectangle(218,128,421,143);
  307.     rectangle(216,126,423,145);
  308.     setcolor(cor[1]);
  309.     rectangle(217,127,422,144);
  310.     rectangle(215,125,424,146);
  311. }
  312.  
  313.  
  314. /* Funcao quadrado **************************************** */
  315.  
  316. void quadrado(void)
  317. {
  318.     setcolor(cor[3]);
  319.     setfillpattern(dentro,cor[3]);
  320.     bar(0,0,19,7);
  321.     setcolor(cor[4]);
  322.     line(2,1,15,1);
  323.     line(2,1,2,5);
  324.     line(3,1,3,5);
  325.     line(18,7,18,1);
  326.     line(19,7,19,1);
  327.     line(19,7,1,7);
  328.     setcolor(cor[0]);
  329.     line(0,0,18,0);
  330.     line(0,0,0,6);
  331.     line(1,1,1,6);
  332.     line(16,6,16,2);
  333.     line(17,6,17,2);
  334.     line(17,6,4,6);
  335.     getimage(0,0,19,7,drops);
  336. }
  337.  
  338.  
  339. /* Funcao jogo ******************************************** */
  340.  
  341. int jogo(void)
  342. {
  343.     int peca,vert1,vert2,vert3,t,deu,num;
  344.     float horiz2;
  345.     cai=0;
  346.     round=1;
  347.     pontos=0;
  348.     volta_round:;
  349.         iround();
  350.         while(kbhit()) getch();
  351.         sorteia:;
  352.             peca=peca1;
  353.             horiz=4;
  354.             vert1=0;
  355.             vert2=4;
  356.             peca1=random(7);
  357.             rotacao=0;
  358.             setfillpattern(dentro,cor[6]);
  359.             bar(351,120,548,168);
  360.             vert3=15;
  361.             horiz2=17.1;
  362.             if (peca1==2)
  363.             {
  364.                 horiz2=17.6;
  365.                 vert2=7;
  366.             }
  367.             if (peca1==4) vert2=0;
  368.             if (prox==1) poe(vert3,vert2,horiz2,peca1,0);
  369.             looping:;
  370.                 vert2=0;
  371.                 for(t=0;t<4;t++)
  372.                 {
  373.                     vert2+=2;
  374.                     poe(vert1,vert2,horiz,peca,rotacao);
  375.                     tir1(vert1,vert2-2,horiz,peca,rotacao);
  376.                     if(teclas(vert1,vert2,peca)==1)return 2;
  377.                     if (cai==1)
  378.                     {
  379.                         tir1(vert1,vert2,horiz,peca,rotacao);
  380.                         vert2=8;
  381.                         tire(vert1-1,vert2,horiz,peca,rotacao);
  382.                         poe(vert1,vert2,horiz,peca,rotacao);
  383.                         break;
  384.                     }
  385.                     else delay(55-3*round);
  386.                 }
  387.             vert1=vert1+1;
  388.             if (bateu(vert1,horiz,peca,rotacao)>0) goto colar;
  389.             goto looping;
  390.         colar:;
  391.         cai=0;
  392.         cola(vert1,horiz,peca,rotacao);
  393.         pontos+=40;
  394.         if(record<pontos)record=pontos;
  395.         score();
  396.         deu=0;
  397.         for(t=1;t<11;t++)deu=deu+malha[t][3];
  398.         if(deu>0)return 0;
  399.         num=desce();
  400.         if(num>0)
  401.         {
  402.             if(num==1)pontos+=200;
  403.             if(num==2)pontos+=600;
  404.             if(num==3)pontos+=1200;
  405.             if(num==4)pontos+=2500;
  406.             linhas-=num;
  407.             if(linhas<0)linhas=0;
  408.             if(record<pontos)record=pontos;
  409.             score();
  410.             if(linhas==0)
  411.             {
  412.                 if(round==10)return 1;
  413.                 pontos+=(long int)5000*round;
  414.                 round++;
  415.                 if(record<pontos)record=pontos;
  416.                 goto volta_round;
  417.             }
  418.         }
  419.         goto sorteia;
  420. }
  421.  
  422.  
  423. /* Funcao iround ****************************************** */
  424.  
  425. void iround(void)
  426. {
  427.     int x,y,a,b,t,r;
  428.     linhas=25;
  429.     peca1=random(7);
  430.     clearviewport();
  431.     settextstyle(TRIPLEX_FONT,HORIZ_DIR,5);
  432.     settextjustify(CENTER_TEXT,CENTER_TEXT);
  433.     setcolor(cor[5]);
  434.     for(x=-1;x<1;x++)
  435.     {
  436.         for(y=-1;y<1;y++)
  437.         {
  438.             a=getmaxx()/2+x;
  439.             b=80+y;
  440.             gprintf(&a,&b,"FASE %i",round);
  441.         }
  442.     }
  443.     while(kbhit()) getch();
  444.     delay(1500);
  445.     clearviewport();
  446.     setcolor(cor[2]);
  447.     rectangle(50,0,589,185);
  448.     settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
  449.     settextjustify(RIGHT_TEXT,BOTTOM_TEXT);
  450.     setcolor(cor[4]);
  451.     outtextxy(590,198,"DROPS versao 2.0 - ZiCauSoft 1993");
  452.     outtextxy(590,197,"~                      ");
  453.     setfillpattern(dentro,cor[0]);
  454.     bar(71,9,90,39);
  455.     bar(291,9,310,39);
  456.     setfillpattern(dentro,cor[3]);
  457.     bar(71,41,90,176);
  458.     bar(91,169,290,176);
  459.     bar(291,41,310,176);
  460.     setfillpattern(dentro,cor[5]);
  461.     bar(331,9,568,16);
  462.     bar(331,17,350,168);
  463.     bar(549,17,568,168);
  464.     bar(331,169,568,176);
  465.     setcolor(cor[8]);
  466.     settextstyle(SMALL_FONT,HORIZ_DIR,6);
  467.     settextjustify(LEFT_TEXT,TOP_TEXT);
  468.     outtextxy(364,18,"PONTOS :");
  469.     outtextxy(364,38,"LINHAS :");
  470.     outtextxy(364,58,"FASE :");
  471.     outtextxy(364,78,"RECORDE :");
  472.     outtextxy(364,103,"PROXIMO :");
  473.     line(387,106,390,103);
  474.     score();
  475.     for(t=0;t<21;t++)
  476.     {
  477.         for(r=0;r<12;r++)
  478.         {
  479.             malha[r][t]=0;
  480.         }
  481.     }
  482.     for(t=0;t<21;t++)
  483.     {
  484.         malha[0][t]=1;
  485.         malha[11][t]=1;
  486.     }
  487.     for(r=1;r<11;r++)
  488.     {
  489.         malha[r][20]=1;
  490.     }
  491. }
  492.  
  493.  
  494. /* Funcao gameover **************************************** */
  495.  
  496. void gameover(void)
  497. {
  498.     int x,y,a,b;
  499.     clearviewport();
  500.     settextstyle(TRIPLEX_FONT,HORIZ_DIR,6);
  501.     settextjustify(CENTER_TEXT,CENTER_TEXT);
  502.     setcolor(cor[5]);
  503.     for(x=-1;x<1;x++)
  504.     {
  505.         for(y=-1;y<1;y++)
  506.         {
  507.             a=getmaxx()/2+x;
  508.             b=80+y;
  509.             gprintf(&a,&b,"FIM DE JOGO!");
  510.         }
  511.     }
  512.     while(kbhit()) getch();
  513.     delay(1500);
  514. }
  515.  
  516.  
  517. /* Funcao final ******************************************* */
  518.  
  519. void final(void)
  520. {
  521.     int x,y,a,b;
  522.     setfillpattern(dentro,cor[6]);
  523.     for(x=0;x<10;x++) for(y=0;y<16;y++)
  524.     {
  525.         bar(y*40,x*20,y*40+39,x*20+19);
  526.         delay(10);
  527.     }
  528.     setcolor(cor[5]);
  529.     settextstyle(SMALL_FONT,HORIZ_DIR,7);
  530.     settextjustify(CENTER_TEXT,TOP_TEXT);
  531.     outtextxy(320,5,"PARABENS, VOCE CONSEGUIU, COM SEUS REFLEXOS E");
  532.     outtextxy(320,25,"SUA HABILIDADE, CHEGAR AO FINAL DE UMA DIFICIL");
  533.     outtextxy(320,45,"VERSAO DE TETRIS. BY CAU E ZIZO:");
  534.     settextstyle(GOTHIC_FONT,HORIZ_DIR,15);
  535.     line(116,8,119,5);
  536.     line(209,8,212,5);
  537.     line(212,5,215,8);
  538.     line(549,28,552,25);
  539.     line(182,48,185,46);
  540.     line(185,46,187,48);
  541.     line(187,48,190,46);
  542.     setcolor(cor[0]);
  543.     outtextxy(319,30,"DROPS");
  544.     outtextxy(320,30,"DROPS");
  545.     outtextxy(318,30,"DROPS");
  546.     outtextxy(321,30,"DROPS");
  547.     outtextxy(317,30,"DROPS");
  548.     setcolor(cor[3]);
  549.     outtextxy(322,31,"DROPS");
  550.     delay(10000);
  551.     clearviewport();
  552.     settextstyle(SMALL_FONT,HORIZ_DIR,7);
  553.     setcolor(cor[7]);
  554.     outtextxy(320,0,"Programado, Estruturado, Desenhado,");
  555.     outtextxy(320,20,"Projetado e Testado by:");
  556.     outtextxy(320,105,"Obrigados Especiais para:");
  557.     settextstyle(TRIPLEX_FONT,HORIZ_DIR,4);
  558.     setcolor(cor[5]);
  559.     outtextxy(320,40,"CAU e ZIZO");
  560.     outtextxy(320,125,"RO, RAFA, BOCON e");
  561.     outtextxy(320,155,"MAMMA OF CAU");
  562.     delay(8000);
  563.     clearviewport();
  564.     settextstyle(TRIPLEX_FONT,HORIZ_DIR,8);
  565.     settextjustify(CENTER_TEXT,CENTER_TEXT);
  566.     setcolor(cor[5]);
  567.     for(x=-1;x<2;x++)
  568.     {
  569.         for(y=-1;y<2;y++)
  570.         {
  571.             a=getmaxx()/2+x;
  572.             b=70+y;
  573.             gprintf(&a,&b,"FIM");
  574.         }
  575.     }
  576.     while(kbhit()) getch();
  577.     delay(4500);
  578. }
  579.  
  580.  
  581. /* Funcao gprintf ***************************************** */
  582.  
  583. int gprintf( int *xloc, int *yloc, char *fmt, ... )
  584. {
  585.   va_list  argptr;
  586.   char str[140];
  587.   int cnt;
  588.  
  589.   va_start( argptr, fmt );
  590.  
  591.   cnt = vsprintf( str, fmt, argptr );
  592.   outtextxy( *xloc, *yloc, str );
  593.   *yloc += textheight( "H" ) + 2;
  594.  
  595.   va_end( argptr );
  596.  
  597.   return( cnt );
  598.  
  599. }
  600.  
  601.  
  602. /* Funcao score ******************************************* */
  603.  
  604. void score(void)
  605. {
  606.     int a,b;
  607.     setcolor(cor[6]);
  608.     settextstyle(SMALL_FONT,HORIZ_DIR,6);
  609.     settextjustify(RIGHT_TEXT,TOP_TEXT);
  610.     a=538;
  611.     b=18;
  612.     setfillpattern(dentro,cor[7]);
  613.     bar(470,22,538,34);
  614.     gprintf(&a,&b,"%li",pontos);
  615.     b=38;
  616.     bar(470,42,538,54);
  617.     gprintf(&a,&b,"%i",linhas);
  618.     b=58;
  619.     bar(470,62,538,74);
  620.     gprintf(&a,&b,"%i",round);
  621.     b=78;
  622.     bar(470,82,538,94);
  623.     gprintf(&a,&b,"%li",record);
  624. }
  625.  
  626.  
  627. /* Funcao poe ********************************************* */
  628.  
  629. void poe(int alt1, int alt2, float hor, int pec, int rot)
  630. {
  631.     int x,x1,y,y1,t,r;
  632.     y=alt1*8+alt2+9;
  633.     x=hor*20+71;
  634.     for(t=0;t<4;t++)
  635.     {
  636.         for(r=0;r<4;r++)
  637.         {
  638.             if(ic[pec][rot][t][r]==1)
  639.             {
  640.                 y1=y+t*8;
  641.                 x1=x+r*20;
  642.                 putimage(x1,y1,drops,COPY_PUT);
  643.             }
  644.         }
  645.     }
  646. }
  647.  
  648.  
  649. /* Funcao tir1 ******************************************** */
  650.  
  651. void tir1(int alt1, int alt2, int hor, int pec, int rot)
  652. {
  653.     int x,x1,y,y1,t,r,a;
  654.     y=alt1*8+alt2+9;
  655.     x=hor*20+71;
  656.     for(t=0;t<4;t++)
  657.     {
  658.         for(r=0;r<4;r++)
  659.         {
  660.             if(t==0) a=0;
  661.             else a=ic[pec][rot][t-1][r];
  662.             if(ic[pec][rot][t][r]==1 && a==0)
  663.             {
  664.                 x1=x+r*20;
  665.                 y1=y+t*8;
  666.                 setcolor(cor[6]);
  667.                 rectangle(x1,y1,x1+19,y1+1);
  668.             }
  669.         }
  670.     }
  671. }
  672.  
  673.  
  674. /* Funcao tire ******************************************** */
  675.  
  676. void tire(int alt1, int alt2, int hor, int pec, int rot)
  677. {
  678.     int x,x1,y,y1,t,r;
  679.     y=alt1*8+alt2+9;
  680.     x=hor*20+71;
  681.     for(t=0;t<4;t++)
  682.     {
  683.         for(r=0;r<4;r++)
  684.         {
  685.             if(ic[pec][rot][t][r]==1)
  686.             {
  687.                 x1=x+r*20;
  688.                 y1=y+t*8;
  689.                 setfillpattern(dentro,cor[6]);
  690.                 bar(x1,y1,x1+19,y1+7);
  691.             }
  692.         }
  693.     }
  694. }
  695.  
  696.  
  697. /* Funcao bateu ******************************************* */
  698.  
  699. int bateu(int alt,int hor, int pec, int rot)
  700. {
  701.     int t,r,x1,y1,bat;
  702.     bat=0;
  703.     hor--;
  704.     for(t=0;t<4;t++)
  705.     {
  706.         for(r=0;r<4;r++)
  707.         {
  708.             x1=hor+t+1;
  709.             y1=alt+r+1;
  710.             if(ic[pec][rot][r][t]==1)bat=bat+malha[x1][y1];
  711.         }
  712.     }
  713.     hor++;
  714.     return bat;
  715. }
  716.  
  717.  
  718. /* Funcao desce ******************************************* */
  719.  
  720. int desce(void)
  721. {
  722.     int num=0,tot,t,r,tt,rr;
  723.     for(t=4;t<20;t++)
  724.     {
  725.         tot=0;
  726.         for(r=1;r<11;r++) if(malha[r][t]>0) tot++;
  727.         if(tot==10) goto desca;
  728.         volta_desca:;
  729.     }
  730.     return num;
  731.     desca:;
  732.     for(tt=t;tt>3;tt--) for(rr=1;rr<11;rr++) malha[rr][tt]=malha[rr][tt-1];
  733.     num=num+1;
  734.     getimage(91,31,290,8+8*t,faixa);
  735.     putimage(91,39,faixa,COPY_PUT);
  736.     goto volta_desca;
  737. }
  738.  
  739.  
  740. /* Funcao cola ******************************************** */
  741.  
  742. void cola(int alt, int hor, int pec, int rot)
  743. {
  744.     int x1,y1,t,r;
  745.     for(t=0;t<4;t++)
  746.     {
  747.         for(r=0;r<4;r++)
  748.         {
  749.             if(ic[pec][rot][r][t]==1) goto cole;
  750.             volta_cole:;
  751.         }
  752.     }
  753.     return;
  754.     cole:;
  755.     x1=hor+t;
  756.     y1=alt+r;
  757.     malha[x1][y1]=1;
  758.     goto volta_cole;
  759. }
  760.  
  761.  
  762. /* Funcao teclas ****************************************** */
  763.  
  764. int teclas(int alt1, int alt2, int pec)
  765. {
  766.     char a1=NULL,a2=NULL;
  767.     int rt1,hor1,cont=0;
  768.     while(kbhit())
  769.     {
  770.         a2=a1;
  771.         a1=getch();
  772.         cont=1;
  773.     }
  774.     if(cont==0)return 0;
  775.     if(a1==32)cai=1;
  776.     if(a1==27)return 1;
  777.     if(a1==13)prox=1+(prox==1);
  778.     if(a2==0 && a1==75)
  779.     {
  780.         hor1=horiz-1;
  781.         if(possivel(alt1,alt2,hor1,pec,rotacao)==0)
  782.         {
  783.             tire(alt1,alt2,horiz,pec,rotacao);
  784.             horiz=hor1;
  785.             poe(alt1,alt2,horiz,pec,rotacao);
  786.         }
  787.     }
  788.     if(a2==0 && a1==77)
  789.     {
  790.         hor1=horiz+1;
  791.         if(possivel(alt1,alt2,hor1,pec,rotacao)==0)
  792.         {
  793.             tire(alt1,alt2,horiz,pec,rotacao);
  794.             horiz=hor1;
  795.             poe(alt1,alt2,horiz,pec,rotacao);
  796.         }
  797.     }
  798.     if(a2==0 && a1==80)
  799.     {
  800.         rt1=rotacao+1;
  801.         if(rt1==4)rt1=0;
  802.         if(possivel(alt1,alt2,horiz,pec,rt1)==0)
  803.         {
  804.             tire(alt1,alt2,horiz,pec,rotacao);
  805.             rotacao=rt1;
  806.             poe(alt1,alt2,horiz,pec,rotacao);
  807.         }
  808.     }
  809.     return 0;
  810.  
  811. }
  812.  
  813.  
  814. /* Funcao possivel **************************************** */
  815.  
  816. int possivel(int alt1, int alt2, int hor, int pec, int rot)
  817. {
  818.     int poss,t,r,y1,x1;
  819.     poss=0;
  820.     if(alt2==8) goto segunda;
  821.     for(t=0;t<4;t++)
  822.     {
  823.         for(r=0;r<4;r++)
  824.         {
  825.             x1=t+hor;
  826.             y1=alt1+r;
  827.             if(((x1<0 || y1<0) || (x1>11 || y1>20)) && ic[pec][rot][r][t]==1)poss=1;
  828.             else if(ic[pec][rot][r][t]==1)poss=poss+malha[x1][y1];
  829.         }
  830.     }
  831.     segunda:;
  832.     for(t=0;t<4;t++)
  833.     {
  834.         for(r=0;r<4;r++)
  835.         {
  836.             x1=t+hor;
  837.             y1=alt1+r+1;
  838.             if(((x1<0 || y1<0) || (x1>11 || y1>20)) && ic[pec][rot][r][t]==1)poss=1;
  839.             else if(ic[pec][rot][r][t]==1)poss=poss+malha[x1][y1];
  840.         }
  841.     }
  842.     return poss;
  843. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement