home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / games / volume6 / tetrix / Rotate.c < prev    next >
C/C++ Source or Header  |  1989-02-28  |  6KB  |  248 lines

  1.  
  2. #include <curses.h>
  3. #include "tet.h"
  4. /*********************************************************************/
  5. /* Switch on type of piece, find out if I can rotate */
  6. /* If so, then do it */
  7. /*********************************************************************/
  8. Rotate()
  9. {
  10. switch (Type) {
  11.     /*  WHITE PIECES  */
  12.     case W_TYPE   :  /* checked */
  13.         if (IS_FREE(Column,Row-1)) {
  14.             PUTCH(Column-1,Row,NO_CHAR);
  15.             PUTCH(Column,Row-1,W_CHAR);
  16.             Type--;
  17.             }
  18.         else goto beepout;
  19.         goto out;
  20.     case W_TYPE-1 :  /* checked */
  21.         if (IS_FREE(Column-1,Row)) {
  22.             PUTCH(Column,Row+1,NO_CHAR);
  23.             PUTCH(Column-1,Row,W_CHAR);
  24.             Type--;
  25.             }
  26.         else goto beepout;
  27.         goto out;
  28.     case W_TYPE-2 :  /* checked */
  29.         if (IS_FREE(Column,Row+1)) {
  30.             PUTCH(Column+1,Row,NO_CHAR);
  31.             PUTCH(Column,Row+1,W_CHAR);
  32.             Type--;
  33.             }
  34.         else goto beepout;
  35.         goto out;
  36.     case W_TYPE-3 :  /* checked */
  37.         if (IS_FREE(Column+1,Row)) {
  38.             PUTCH(Column,Row-1,NO_CHAR);
  39.             PUTCH(Column+1,Row,W_CHAR);
  40.             Type = W_TYPE;
  41.             }
  42.         else goto beepout;
  43.         goto out;
  44.  
  45.     /*  RED PIECES  */
  46.     case R_TYPE   : /* checked */
  47.         if (IS_FREE(Column,Row-1) && IS_FREE(Column,Row+1) && 
  48.             IS_FREE(Column+1,Row+1)) {
  49.             PUTCH(Column-1,Row,NO_CHAR);
  50.             PUTCH(Column-1,Row+1,NO_CHAR);
  51.             PUTCH(Column+1,Row,NO_CHAR);
  52.             PUTCH(Column,Row-1,R_CHAR);
  53.             PUTCH(Column,Row+1,R_CHAR);
  54.             PUTCH(Column+1,Row+1,R_CHAR);
  55.             Type--;
  56.             }
  57.         else goto beepout;
  58.         goto out;
  59.     case R_TYPE-1 : /* checked */
  60.         if (IS_FREE(Column-1,Row) && IS_FREE(Column+1,Row-1) && 
  61.             IS_FREE(Column+1,Row)) {
  62.             PUTCH(Column,Row-1,NO_CHAR);
  63.             PUTCH(Column,Row+1,NO_CHAR);
  64.             PUTCH(Column+1,Row+1,NO_CHAR);
  65.             PUTCH(Column-1,Row,R_CHAR);
  66.             PUTCH(Column+1,Row-1,R_CHAR);
  67.             PUTCH(Column+1,Row,R_CHAR);
  68.             Type--;
  69.             }
  70.         else goto beepout;
  71.         goto out;
  72.     case R_TYPE-2 : /* checked  */
  73.         if (IS_FREE(Column-1,Row-1) && IS_FREE(Column,Row-1) && 
  74.             IS_FREE(Column,Row+1)) {
  75.             PUTCH(Column-1,Row,NO_CHAR);
  76.             PUTCH(Column+1,Row-1,NO_CHAR);
  77.             PUTCH(Column+1,Row,NO_CHAR);
  78.             PUTCH(Column-1,Row-1,R_CHAR);
  79.             PUTCH(Column,Row-1,R_CHAR);
  80.             PUTCH(Column,Row+1,R_CHAR);
  81.             Type--;
  82.             }
  83.         else goto beepout;
  84.         goto out;
  85.     case R_TYPE-3 : /* checked */
  86.         if (IS_FREE(Column-1,Row) && IS_FREE(Column-1,Row+1) && 
  87.             IS_FREE(Column+1,Row)) {
  88.             PUTCH(Column-1,Row-1,NO_CHAR);
  89.             PUTCH(Column,Row-1,NO_CHAR);
  90.             PUTCH(Column,Row+1,NO_CHAR);
  91.             PUTCH(Column-1,Row,R_CHAR);
  92.             PUTCH(Column-1,Row+1,R_CHAR);
  93.             PUTCH(Column+1,Row,R_CHAR);
  94.             Type = R_TYPE;
  95.             }
  96.         else goto beepout;
  97.         goto out;
  98.  
  99.     /*  TAN PIECES  */
  100.     case T_TYPE   :
  101.     case T_TYPE-1 :
  102.     case T_TYPE-2 :
  103.     case T_TYPE-3 : goto out;
  104.  
  105.     /*  YELLOW PIECES  */
  106.     case Y_TYPE   :
  107.     case Y_TYPE-2 :  /* checked */
  108.         if (IS_FREE(Column,Row-1) && IS_FREE(Column+1,Row+1)) {
  109.             PUTCH(Column-1,Row+1,NO_CHAR);
  110.             PUTCH(Column,Row+1,NO_CHAR);
  111.             PUTCH(Column,Row-1,Y_CHAR);
  112.             PUTCH(Column+1,Row+1,Y_CHAR);
  113.             Type--;
  114.             }
  115.         else goto beepout;
  116.         goto out;
  117.     case Y_TYPE-1 :
  118.     case Y_TYPE-3 : /* checked */
  119.         if (IS_FREE(Column-1,Row+1) && IS_FREE(Column,Row+1)) {
  120.             PUTCH(Column,Row-1,NO_CHAR);
  121.             PUTCH(Column+1,Row+1,NO_CHAR);
  122.             PUTCH(Column-1,Row+1,Y_CHAR);
  123.             PUTCH(Column,Row+1,Y_CHAR);
  124.             Type = Y_TYPE;
  125.             }
  126.         else goto beepout;
  127.         goto out;
  128.  
  129.     /*  GREEN PIECES  */
  130.     case G_TYPE   :
  131.     case G_TYPE-2 : /* checked */
  132.         if (IS_FREE(Column-1,Row+1) && IS_FREE(Column,Row-1)) {
  133.             PUTCH(Column,Row+1,NO_CHAR);
  134.             PUTCH(Column+1,Row+1,NO_CHAR);
  135.             PUTCH(Column-1,Row+1,G_CHAR);
  136.             PUTCH(Column,Row-1,G_CHAR);
  137.             Type--;
  138.             }
  139.         else goto beepout;
  140.         goto out;
  141.     case G_TYPE-1 :
  142.     case G_TYPE-3 : /* checked */
  143.         if (IS_FREE(Column,Row+1) && IS_FREE(Column+1,Row+1)) {
  144.             PUTCH(Column-1,Row+1,NO_CHAR);
  145.             PUTCH(Column,Row-1,NO_CHAR);
  146.             PUTCH(Column,Row+1,G_CHAR);
  147.             PUTCH(Column+1,Row+1,G_CHAR);
  148.             Type = G_TYPE;
  149.             }
  150.         else goto beepout;
  151.         goto out;
  152.  
  153.  
  154.     /*  BLUE PIECES  */
  155.     case B_TYPE   : /* checked */
  156.         if (IS_FREE(Column,Row-1) && IS_FREE(Column,Row+1) && 
  157.             IS_FREE(Column+1,Row-1)) {
  158.             PUTCH(Column-1,Row,NO_CHAR);
  159.             PUTCH(Column+1,Row,NO_CHAR);
  160.             PUTCH(Column+1,Row+1,NO_CHAR);
  161.             PUTCH(Column,Row-1,B_CHAR);
  162.             PUTCH(Column,Row+1,B_CHAR);
  163.             PUTCH(Column+1,Row-1,B_CHAR);
  164.             Type--;
  165.             }
  166.         else goto beepout;
  167.         goto out;
  168.     case B_TYPE-1 : /* checked */
  169.         if (IS_FREE(Column-1,Row-1) && IS_FREE(Column-1,Row) && 
  170.             IS_FREE(Column+1,Row)) {
  171.             PUTCH(Column,Row-1,NO_CHAR);
  172.             PUTCH(Column,Row+1,NO_CHAR);
  173.             PUTCH(Column+1,Row-1,NO_CHAR);
  174.             PUTCH(Column-1,Row-1,B_CHAR);
  175.             PUTCH(Column-1,Row,B_CHAR);
  176.             PUTCH(Column+1,Row,B_CHAR);
  177.             Type--;
  178.             }
  179.         else goto beepout;
  180.         goto out;
  181.     case B_TYPE-2 : /* checked  */
  182.         if (IS_FREE(Column-1,Row+1) && IS_FREE(Column,Row-1) && 
  183.             IS_FREE(Column,Row+1)) {
  184.             PUTCH(Column-1,Row-1,NO_CHAR);
  185.             PUTCH(Column-1,Row,NO_CHAR);
  186.             PUTCH(Column+1,Row,NO_CHAR);
  187.             PUTCH(Column-1,Row+1,B_CHAR);
  188.             PUTCH(Column,Row-1,B_CHAR);
  189.             PUTCH(Column,Row+1,B_CHAR);
  190.             Type--;
  191.             }
  192.         else goto beepout;
  193.         goto out;
  194.     case B_TYPE-3 : /* checked */
  195.         if (IS_FREE(Column-1,Row) && IS_FREE(Column+1,Row) && 
  196.             IS_FREE(Column+1,Row+1)) {
  197.             PUTCH(Column-1,Row+1,NO_CHAR);
  198.             PUTCH(Column,Row-1,NO_CHAR);
  199.             PUTCH(Column,Row+1,NO_CHAR);
  200.             PUTCH(Column-1,Row,B_CHAR);
  201.             PUTCH(Column+1,Row,B_CHAR);
  202.             PUTCH(Column+1,Row+1,B_CHAR);
  203.             Type = B_TYPE;
  204.             }
  205.         else goto beepout;
  206.         goto out;
  207.  
  208.     /*  VIOLET PIECES  */
  209.     case V_TYPE   :
  210.     case V_TYPE-2 : /* checked */
  211.         if (IS_FREE(Column,Row-1) && IS_FREE(Column,Row+1) && 
  212.             IS_FREE(Column,Row+2)) {
  213.             PUTCH(Column-1,Row,NO_CHAR);
  214.             PUTCH(Column+1,Row,NO_CHAR);
  215.             PUTCH(Column+2,Row,NO_CHAR);
  216.             PUTCH(Column,Row-1,V_CHAR);
  217.             PUTCH(Column,Row+1,V_CHAR);
  218.             PUTCH(Column,Row+2,V_CHAR);
  219.             Type--;
  220.             }
  221.         else goto beepout;
  222.         goto out;
  223.     case V_TYPE-1 :
  224.     case V_TYPE-3 : /* checked */
  225.         if (IS_FREE(Column-1,Row) && IS_FREE(Column+1,Row) && 
  226.             IS_FREE(Column+2,Row)) {
  227.             PUTCH(Column,Row-1,NO_CHAR);
  228.             PUTCH(Column,Row+1,NO_CHAR);
  229.             PUTCH(Column,Row+2,NO_CHAR);
  230.             PUTCH(Column-1,Row,V_CHAR);
  231.             PUTCH(Column,Row,V_CHAR);
  232.             PUTCH(Column+1,Row,V_CHAR);
  233.             PUTCH(Column+2,Row,V_CHAR);
  234.             Type = V_TYPE;
  235.             }
  236.         else goto beepout;
  237.         goto out;
  238.     default : 
  239.         printf("illegal piece Type=%d!!\n",Type); 
  240.         exit();
  241.     }
  242. beepout:
  243.     if (Beep) beep();
  244. out:
  245.     refresh();
  246. }
  247.  
  248.