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

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