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

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