home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / games / pcgamn6.zip / BG0.C < prev    next >
C/C++ Source or Header  |  1986-09-10  |  10KB  |  299 lines

  1.  
  2. /* 
  3. ** bg0.c -- contains main() and globals
  4. *
  5.  
  6.    Program  : PC-Gammon IV
  7.    Computer : 100% IBM PC compatibles 
  8.    Language : Microsoft C 4.00
  9.             :
  10.    Compile  : cl -Febackgmmn bg0.c bg1.c bg2.c bg3.c -link ciao
  11.             :
  12.    Files    : backgmmn.h    private declarations file
  13.             : backgmmn.doc  history file
  14.             : bg0.c         main(), global data
  15.             : bg1.c         utilities
  16.             : bg2.c         board & dice manager
  17.             : bg3.c         gameplan & strategy manager
  18.             : ciao.h        declarations for fast RAM version of...
  19.             : ciao.lib      ibm clone i/o module
  20.             : backgmmn.     make file, optional
  21.             :
  22.    Author   : David C. Oshel
  23.             : 1219 Harding Avenue
  24.             : Ames, Iowa 50010
  25. *           : September 8, 1986
  26. **
  27. */
  28.  
  29.  
  30. #include "backgmmn.h"   /* private declarations file */
  31.  
  32.  
  33.  
  34. /* Note:  ALL version info is located here, from now on! 
  35. */
  36.  
  37. #define USERMAN "pc-gamn6.doc"
  38.  
  39. char *bgversion = ".61  Sept. 10, 1986, by David C. Oshel";
  40.                  /*....v....1....v....2....v....3....v...*/
  41.                  /* just 38 characters for version info! */
  42.  
  43. char *logoname = "PC-GAMMON:  The Peelgrunt Game of Gammon IV v. 6.1";
  44.  
  45.  
  46.  
  47. /* Global Data 
  48. */ 
  49.  
  50. int level = 3;
  51.  
  52. jmp_buf mark;
  53.  
  54. char *backtalk[] = {
  55.      "VILLIERS:  At your service!",
  56.      "LOUISA:  Delighted!",
  57.      "TORVE:  Is interesting line of occurrence.  Thurb!",
  58.      "Copyright (c) 1985 by The Xochitl Sodality Wonders & Marvels Committee",
  59.      };
  60.  
  61. int list[2][28];  /* two dice, two lists */
  62.  
  63. struct board point[28], bdsave[28]; /* 24 points, plus 2 bars, 2 homes */
  64. struct dstruct doubles;
  65. struct pstruct pending;
  66.  
  67. int dice[2], myscore, yrscore, player, movesleft, cantuse, myturns,
  68.     swapped, tswap, deciding, expert, show, moremsgline, 
  69.     tokenstyle, firstmove, helpdisabled, yrdice, lookforit, startcubevalue;
  70.  
  71. char *token1, *token2, chatter[80], buzzard[80], window[80];
  72.  
  73.  
  74.  
  75.  
  76.  
  77. commands() {
  78.  
  79. static char ch;
  80.  
  81. static char *p1 = "^φP^lay, ^φA^rrange, ^φN^ew, ^φR^everse, ^φS^wap, ^φH^%s, ^φQ^uit ",
  82.             *p2 = "^φU^se %s dice, ^φO^pponent, ^φX^pert, ^φT^one, ^φC^ount, ^φZ^ero, ^φQ^uit ",
  83.             *myline;
  84.  
  85.  
  86.      level = MYLEVEL + 1; /* fetch copyright notice */
  87.      setup(); 
  88.      hint();
  89.  
  90.      while (TRUE) {
  91.           moremsgline = FALSE;  /* show first command line on entry */
  92.           myline = backtalk[ level ];  /* did level change? */
  93.           msg(5,23, myline );
  94.           firstmove = TRUE;
  95.           newboard(); /* note, sets starting cube value to 1 */
  96.  
  97.           deciding = TRUE;
  98.           while (deciding) {
  99.  
  100.           /* display command line */
  101.  
  102.           off_cursor(); 
  103.           if (show) { mytotal(); yrtotal(); }
  104.           else { gotoxy(0,3); wprintf("   "); gotoxy(0,19); wprintf("   "); }
  105.           if (tone) beep();
  106.           if (expert) {
  107.                msg(5,22,"");
  108.                msg(5,23,"Your pleasure? ");
  109.                }
  110.           else {
  111.                if (moremsgline) 
  112.                {
  113.                     msg(5,22,"^");
  114.                     msg(5,23,  "Select:  ");
  115.                     wprintf( p2, (yrdice? "my": "your")); 
  116.                }
  117.                else 
  118.                {
  119.                     msg(5,22,"^");
  120.                     msg(5,23,  "Select:  ");
  121.                     wprintf( p1, (vid_mode == 7? "ilite": "ues"));
  122.                }
  123.           }
  124.  
  125.           /* get response and do it */
  126.  
  127.  
  128.           ch = keyin( acg );
  129.           ch = toupper( ch );
  130.  
  131.           if (moremsgline && ch < -60) ch += 35;  /* Shift Fn Key */
  132.  
  133.           switch ( ch ) {
  134.                case -60:    /* F10 */
  135.                case 'Q': {  /* quit play, exit to system */
  136.                     return;
  137.                     }
  138.                case -69:    /* F1 */ 
  139.                case 'P': {  /* play the game as board is arranged */
  140.                     helpdisabled = FALSE;
  141.                     if (level > MYLEVEL ) {
  142.                          myline = chooseplayer();
  143.                          update();
  144.                     }
  145.                     play(); 
  146.                     break;
  147.                     }
  148.                case -68:    /* F2 */
  149.                case 'A': {  /* arrange stones (or cheat?) */
  150.                             /* play is suspended, so don't use the long */
  151.                             /* messages that assist game play */
  152.                     helpdisabled = TRUE;
  153.                     arrange();
  154.                     msg(5,22,"");
  155.                     break;
  156.                     }
  157.                case -67:    /* F3 */
  158.                case 'N': {  /* abandon game without quitting */
  159.                     deciding = FALSE; player = 0;
  160.                     break;
  161.                     }
  162.                case -66:    /* F4 */
  163.                case 'R': {  /* mirror board image */
  164.                     reverse();
  165.                     update();
  166.                     break;
  167.                     }
  168.                case -65:    /* F5 */ 
  169.                case 'S': {  /* SWAP Command - exchange stones */
  170.                     swaptokens();
  171.                     update(); 
  172.                     break;
  173.                     }
  174.                case -64:  /* F6, hue or hilite */ 
  175.                case 'H':
  176.                     {
  177.                     /* Note:  Has the user set up a PLAIN board with no
  178.                     ** distinctions between pieces or playing field, and 
  179.                     ** is now going back to something more distinctive?
  180.                     ** Clairol will set the new colors EVERYWHERE the old
  181.                     ** colors were found, regardless, so we update the
  182.                     ** board if an ambiguity was detected on entry.
  183.                     ** Any problems from there on are the user's own, and
  184.                     ** plainly obvious...!  We COULD of course just update
  185.                     ** the board unconditionally, but that sort of spoils
  186.                     ** the illusion.
  187.                     */
  188.                     clairol();
  189.                     if (ambiguity) update();  /* neat & sweet */
  190.                     break;
  191.                     }
  192.                case -24:
  193.                case -34:    /* Shift, ALT, CTL F1 */
  194.                case -44:
  195.                case 'D': {  /* use my dice or your dice? */
  196.                case 'U':
  197.                     yrdice ^= TRUE;
  198.                     break;
  199.                     }
  200.                case -23:    
  201.                case -33:    /* Shift, ALT, CTL F2 */
  202.                case -43:
  203.                case 'O': {  /* change opponents and skill level */
  204.                     myline = chooseplayer();
  205.                     deciding = FALSE;
  206.                     break;
  207.                     }
  208.                case -22:
  209.                case -32:   /* Shift, ALT, CTL F3 */
  210.                case -42:
  211.                case 'X': { /* expert mode toggle(s) */ 
  212.                     expert ^= TRUE; 
  213.                     break;
  214.                     }
  215.                case -21:
  216.                case -31:   /* Shift, ALT, CTL F4 */
  217.                case -41:
  218.                case 'T': { /* kill the beep */
  219.                     tone ^= TRUE; break;
  220.                     }
  221.                case -20:
  222.                case -30:    /* Shift, ALT, CTL F5 */
  223.                case -40:
  224.                case 'C': {  /* show mytotal, yrtotal counts */
  225.                     show ^= TRUE;
  226.                     break;
  227.                     }
  228.                case -19:
  229.                case -29:   /* Shift, ALT, CTL F6 */
  230.                case -39:
  231.                case 'Z': { /* zero the score */
  232.                     myscore = yrscore = 0; putscore();
  233.                     break;
  234.                     }
  235.                case 27 : {
  236.                     moremsgline = expert = FALSE;
  237.                     break;
  238.                     }
  239.                default:  { moremsgline ^= TRUE; break; }
  240.           }}
  241.      }
  242. } /* end: commands */
  243.  
  244.  
  245. main( argc, argv ) int argc; char *argv[];
  246. {
  247.      char far *buffer;
  248.      union REGS rg;
  249.  
  250.      if (argc > 1)        /* as in, A>backgmmn b&w */
  251.      {
  252.          vid_init( 2 );   /* first, foremost, and forever! */
  253.      }
  254.      else
  255.          vid_init( 3 );   /* first, foremost, and forever! */
  256.  
  257.      vid[10] = vid[0];    /* set absolute normal, ^Ω */
  258.      vid[13] = vid[1];    /* set absolute bold,   ^φ */
  259.  
  260.      buffer = savescreen( &rg );
  261.  
  262.      /* writer's block */
  263.      {
  264.           char ch;
  265.  
  266.           if ( (access(USERMAN,0)) != -1 )
  267.           { 
  268.                wputs("\n");
  269.                wputs("*** Do you want to read the PC-Gammon User's Manual? ");
  270.                do
  271.                {
  272.                     ch = keyin( noop );
  273.                     ch = toupper(ch);
  274.                }
  275.                while ((ch != 'Y') && (ch != 'N')); 
  276.                wink(ch);
  277.                if (ch == 'Y') typeafile( USERMAN, 1, 0,0, 79,24 ); 
  278.           }
  279.           else
  280.           {
  281.                windowbox( 25,11,55,15 );
  282.                wprintf( " Ahem...%c\n\n",19);
  283.                wprintf( " The PC-Gammon User's Manual,\n");
  284.                wprintf( " \"%s,\" isn't in this\n",USERMAN);
  285.                wprintf( " directory%c",19);
  286.                sleep(40);
  287.           }
  288.      }
  289.  
  290.      commands();
  291.  
  292.      restorescreen( buffer, &rg );
  293.      vid_exit();
  294.      exit(0);
  295. }
  296.  
  297. /* eof: bg0.c */
  298.  
  299.