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

  1. /*
  2. **  bg1.c  - globals and utilities
  3. */
  4.  
  5. #include "backgmmn.h"
  6. #include <malloc.h>
  7. #include <stdarg.h>
  8.  
  9.  
  10.  
  11.  
  12. /* Utilities */
  13.  
  14.  
  15.  
  16.  
  17. unsigned acg() {  /* additive congruential generator for pseudo-random numbers */
  18. static unsigned arg[] = {
  19.           4292,     60,     4947,     3972,     4489,
  20.           1917,     3916,   7579,     3048,     6856,
  21.           1832,     7589,   1798,     4954,     2880,
  22.           5142,     5187,   3045,     1529,     3110,
  23.           4333,     167,    5556,     7237,     5906,
  24.           5419,     6632,   5833,     3760,     1081,
  25.           1434,     80,     6212,     344,      7303,
  26.           3044,     7675,   5420,     457,      3434,
  27.           2657,     700,    6777,     4436,     620,
  28.           2129,     629,    3550,     1639,     4546,
  29.           1220,     6469,   862,      3280,     4664
  30.      };
  31. static int rp1 = 0, rp2 = 32;
  32.  
  33.      rp1++; 
  34.      rp2++;  
  35.      rp1 %= 55; 
  36.      rp2 %= 55;
  37.      arg[rp1] ^= arg[rp2];
  38.      return ( arg[rp1] );
  39.      
  40. } /* end: acg */
  41.  
  42.  
  43.  
  44.  
  45. int contains( p, q ) char *p, *q;  /* TRUE iff some char from q is in p */
  46. {
  47.      char *k;
  48.      k = strpbrk( p,q );
  49.      return (k != NULL);
  50. }
  51.  
  52.  
  53.  
  54. int max( n,m ) int n,m;
  55. {
  56.     if ( n > m ) return (n); else return (m);
  57. }
  58.  
  59.  
  60.  
  61. int min( n,m ) int n,m;
  62. {
  63.     if ( n < m ) return (n); else return (m);
  64. }
  65.  
  66.  
  67.  
  68. /*
  69. **  special sound effects for backgammon
  70. */
  71.  
  72.  
  73.  
  74.  
  75. void voice( n ) int n;
  76. {
  77.      switch (n)
  78.      {
  79.           case 0: { blopbloop(); break; }
  80.           case 1: { bopbleet();  break; }
  81.           case 2: { thurb();     break; }
  82.           default:  bopbleet();
  83.      } 
  84. }
  85.  
  86.  
  87.  
  88. void beep()
  89. {
  90.      voice ( level );
  91. }
  92.  
  93.  
  94.  
  95. /* 
  96. ** normal set of playing tokens
  97. */
  98.  
  99. char *get2tkn() 
  100. {
  101.     return ("^1()^");
  102. }
  103.  
  104. char *get1tkn() 
  105. {
  106.     return ("^2[]^"); 
  107. }
  108.  
  109. char *get3tkn() 
  110. {
  111.     return ("^2▀▀^");
  112. }
  113.  
  114. char *get4tkn() 
  115. {
  116.     return ("^1≡≡^"); 
  117. }
  118.  
  119.  
  120.  
  121.  
  122. /*
  123. ** hilited alternate set of playing tokens
  124. */
  125.  
  126. char *get6tkn() 
  127. {
  128.     return ("^2()^");
  129. }
  130.  
  131. char *get5tkn() 
  132. {
  133.     return ("^1[]^"); 
  134. }
  135.  
  136. char *get7tkn() 
  137. {
  138.     return ("^1▄▄^");
  139. }
  140.  
  141. char *get8tkn() 
  142. {
  143.     return ("^2≡≡^"); 
  144. }
  145.  
  146.  
  147.  
  148. /*
  149. **  Gammon IV version, logo, title
  150. */
  151.  
  152. void msg( x,y,p ) int x,y; char *p;  /* variable args, works like wprintf */
  153. {
  154.      va_list arg_ptr;
  155.      char *buff;
  156.  
  157.      gotoxy( x,y ); 
  158.      buff = malloc( 128 );
  159.      va_start(arg_ptr, p);
  160.      vsprintf( buff, p, arg_ptr );
  161.      va_end( arg_ptr );
  162.      wputs( buff );
  163.      free( buff );
  164.      clr_eol();
  165.      on_cursor(); /* expect user response */
  166. }
  167.  
  168.  
  169. void title()
  170. {
  171.    clr_screen();
  172.    setwindow( 13,3,65,18 );
  173.    clrwindow();
  174.    gotoxy(0,15);
  175.    wprintf("%s\n\n",logoname);
  176.    wputs("┌────────────────────────────────────────────────┐\n");
  177.    wputs("│░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓│\n");
  178.    wputs("╘══════════════════════════════════════════════╕░│\n");
  179.    wputs("┌─┐ █   ███ ██ █ ██  █   █ ███ █  ███ ███ ██ tm╘═╛\n");
  180.    wputs("│▓└─█─────█─█─██─█─█─█─────█───█───█──██──█─█────┐\n");
  181.    wputs("╘═══█═══███═█══█═██══█═══█═█═█═███═█══█═══███══╕▓│\n");
  182.    wputs("┌─┐ ███ ███ █  █ █   ███ █ ███ █ █ █  ███ █  █ ╘═╛\n");
  183.    wputs("│░└──────────────────────────────────────────────┐\n");
  184.    wputs("│▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░│\n");
  185.    wputs("╘════════════════════════════════════════════════╛\n\n");
  186.    wputs("Copyright (c) 1986 by The LampLighter Software Co.^");
  187.    sleep(30);
  188.    fullscreen();
  189. }
  190.  
  191.  
  192. /* 
  193. **  bg2.c  - globals, chooseplayer()
  194. */
  195.  
  196.  
  197.  
  198.  
  199. /*======================================================================
  200.  
  201.   Choose Player -- A little scenario, in which to select level of play
  202.  
  203. ========================================================================*/
  204.  
  205. void dissemble() {
  206. static int line;
  207. static char *story[] =
  208. {
  209.  "You are a passenger in the \"Orion\" bound for STAR WELL, a slightly disreputable\n",
  210.  "planetoid in the Flammarion Rift, where you have a scheduled layover of several\n",
  211.  "hours.  You enter the Casino there, desperately bored.  Your attention is \n",
  212.  "immediately drawn to an unusual trio.  Your instinct for good company (they \n",
  213.  "are playing Backgammon) leads you easily into a round of introductions:\n",
  214.  "\n",
  215.  "^φLOUISA PARINI^ -- A young woman who gives you the uncomfortable feeling that she\n",
  216.  "is even younger than she looks.  In fact, she is the offspring of a clan of\n",
  217.  "noted interstellar jewel thieves and con artists, on her way to a famous\n",
  218.  "girl's finishing school on Nashua.  She has larceny in her soul, but she is on\n",
  219.  "holiday.  Do not underestimate her.  (But you will, of course.  You must.)\n",
  220.  "\n",
  221.  "^φANTHONY VILLIERS^ -- A mysterious young fop with impeccable manners, and (you\n",
  222.  "notice) an even more impeccable dueling saber at his side.  There is something\n",
  223.  "between Louisa and him.  His conversation is light, witty and just slightly\n",
  224.  "cynical, but you are not wrong to conclude that this is someone you can trust.\n",
  225.  "\n",
  226.  "^φTORVE THE TROG^ --  This blue-eyed, golden-furred entity is a member of the most\n",
  227.  "dangerous and unpredictable race in the galaxy (aside from humans).  You are \n",
  228.  "amazed that this one is allowed to travel. (In fact, Torve's papers were forged\n",
  229.  "by a member of Louisa's family and procured for him by Villiers).  Torve is\n",
  230.  "lost in some inner rapture, emitting soft \"Thurb\"-like noises.\n"
  231. };
  232.  
  233.      clr_screen();
  234.      for ( line = 0; line < 22; line++ )
  235.      {
  236.           wprintf( story[ line ] );
  237.      }
  238.      wprintf ( "(Hit any key to continue)");
  239.      keyin( acg ); 
  240.      for ( line = 0; line < 25; line++ ) 
  241.      {
  242.           wink('\b');
  243.      }
  244.      clr_eol();
  245.     
  246.      wprintf("\nYou suggest a friendly game of backgammon, at small stakes, and your\n");
  247.      wprintf("companions agree instantly.");
  248.      beep();
  249.      wprintf("  Who will be your opponent?  (L, V, or T) ");
  250.  
  251. } /* end: dissemble */
  252.  
  253.  
  254.  
  255. char *chooseplayer() {
  256. int ch; char *q;
  257.  
  258.      dissemble();
  259. loo: ch = keyin( acg );
  260.      ch = toupper(ch);
  261.      switch (ch) {
  262.           case 'A':
  263.           case 'V': { level = 0; break; }
  264.           case 'L':
  265.           case 'P': { level = 1; break; }
  266.           case 'T': { level = 2; break; }
  267.           default:  goto loo;
  268.      }
  269.      q = backtalk[ level ];
  270.      clr_screen(); draw_board(q);
  271.      return(q);
  272.  
  273. } /* end: chooseplayer */
  274.  
  275.  
  276.  
  277.  
  278.  
  279. /* eof: bg1.c */
  280.  
  281.