home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1940 < prev    next >
Encoding:
Internet Message Format  |  1990-12-28  |  19.3 KB

  1. From: cs00chs@unccvax.uncc.edu (charles spell)
  2. Newsgroups: alt.sources
  3. Subject: Atlantic City blackjack v1.0
  4. Message-ID: <2833@unccvax.uncc.edu>
  5. Date: 11 Oct 90 23:37:03 GMT
  6.  
  7.  
  8.  
  9. Here is an Atlantic city blackjack game I hacked together one weekend before
  10. going to Atlantic City. To compile (System V only):
  11.  
  12.      cc bj.c -o bj -lcurses
  13.  
  14. A small contribution will be appreciated...I will send out fixes/enhancements
  15. if there is enough monetary interest...
  16.  
  17. ---cut here---cut here---cut here---cut here---cut here---cut here---cut here-
  18. #include <curses.h>
  19. #include <ctype.h>
  20. #include <signal.h>
  21. /*****************************************************************************
  22. * You may freely distribute this file as long as the contents of this file
  23. * have not been altered in any way or form. If you decide that you would like
  24. * to re-distribute a change, please send to me for testing first - this keeps
  25. * one current tested version out there...
  26. *
  27. * If you enjoy or find the program (in part or whole) useful,
  28. * please send a contribution to:
  29. *   John J. Ribera, Jr.
  30. *   9505-J University Terrace Dr.
  31. *   Charlotte, NC 28262
  32. *   Voice: (704) 549-5571
  33. * Please send suggestions, comments, complaints, ideas, etc... to the author
  34. * at the address above or e-mail : uunet!mcnc!unccvax!cs00chs
  35. */
  36.  
  37. /*****************************************************************************
  38. * NAME                                                                  Oct 90
  39. *   bj - a blackjack program
  40. *
  41. * SYNOPSIS
  42. *   bj
  43. *
  44. * DESCRIPTION
  45. *  This is an eight-deck Atlantic City blackjack game for system V. Splits and
  46. *  double downs are supported. No insurance. Use the Spacebar to Hit and CR to
  47. *  stand if desired. A redeal will occur when half of the all decks are used.
  48. *  bj uses terminfo GRAPHICS capablities - iff they are activated.
  49. *
  50. * NOTE
  51. *  The program looks much nicer if you have the smacs=, rmacs= and acsc=
  52. *  capabilities in your terminfo database...but it will still work
  53. *  without them...
  54. *
  55. *  How to add graphics capabilities for vt100, vt101 and vt102 emulators:
  56. *  Type the following commands (re-start here if anything goes wrong):
  57. *  csh> setenv TERM vt100      # vt100 is an example-use TERM name youre that
  58. *  csh> mkdir ~/term           #   emulates a vt10[012] (in terminfo database)
  59. *  csh> infocmp > ~/term/info  # this will create a terminfo source file.
  60. *  csh> setenv TERMINFO ~/term # Tell curses to use the database in ~/term
  61. *  csh> tic ~/term/info        # Ignore warnings (if any)...
  62. *  Edit the ~/term/info file and add the following line to the proper entry:
  63. *    -go to the entry that emulates vt100 (eg. vt100,vt101, vt102)
  64. *    -add the following line to it...
  65. *    smacs=\E(0\E)0, rmacs=\E(B\E)B, acsc=jjkkllmmnnqqssttuuvvww++\,\,,
  66. *    -save it and type the following command:
  67. *  csh> tic ~/term/info
  68. *
  69. *  For non vt100 emulators you must read your terminal reference manual and
  70. *  terminfo(5) to set it up properly. Some old terminals do not have a text
  71. *  graphics mode - i.e. you cannot see the pretty graphics.
  72. *
  73. * BUGS
  74. *  There are a few bugs. These will be fixed on the next version iff there is
  75. *  enough mmonetary interest. The dealer continues to deal to himself even
  76. *  after the outcome of a score is certain. No insurance. After the first
  77. *  shuffle, the WIN-LOSE is not displayed properly.
  78. *
  79. * AUTHOR
  80. *
  81. *   (E-mail: uunet!mcnc!unccvax!cs00chs)
  82. *   John J. Ribera, Jr.
  83. *   9505-J University Terrace Dr.
  84. *   Charlotte, NC 28262
  85. *   Voice: (704) 549-5571
  86. *
  87. *   If you find this program or any part of it useful please send a
  88. *   contribution to the above address. This will allow you to receive
  89. *   the most recent fixes and versions. Make checks payable to
  90. *   John J. Ribera, Jr.
  91. */
  92.  
  93. /* flags for get_str() and get_chr()... */
  94. #define CLR_FLD     0x0001
  95. #define INIT_ONKEY  0x0010
  96. #define MAP_UPPER   0x0002
  97. #define MAP_LOWER   0x0004
  98. #define AUTO_RET    0x0008
  99. #define NOPAD       0x0020
  100. #define NOECHO      0x0040
  101. #define BEEP        0x0080
  102.  
  103. /* keystroke defines for readablity.... */
  104. #define ESC         0x1b
  105. #define CR          '\r'
  106. #define NL          '\n'
  107. #define BS          '\b'
  108.  
  109. #define MAX_HANDS   3
  110. #define DECKS       8
  111. #define DEALER      0
  112. #define DOWN        0
  113. #define UP          1
  114. #define WIN         0x0001
  115. #define LOSE        0x0002
  116. #define PUSH        0x0004
  117. #define BJ          0x0008
  118. #define GETCNT(i)   (short) abs((int) (getcnt(i)))
  119. typedef struct
  120.     {
  121.     short   amt;
  122.     short   bet;
  123.     short   cnt;
  124.     short   cards[13];
  125.     char    name[9+1];
  126.     WINDOW  *win;
  127.     } HAND;
  128.  
  129. HAND    Hand[MAX_HANDS];
  130. short   Hands = 2;
  131. short   *Cards;
  132. short   Cur_card;
  133. main()
  134. {
  135.     short   i, n, cnt, pcnt, dcnt;
  136.     short   decks, cmp, bet;
  137.     short   *cards, *shuffle();
  138.     short   getcnt(), bj(), getbet();
  139.     char    *cardtype();
  140.     char    input[3], *ptr;
  141.     void    done();
  142.     void    inithand(), disphand();
  143.  
  144. signal(SIGINT, done);
  145. initscr();
  146. noecho();
  147. crmode();
  148.  
  149. for (n = 0; n < MAX_HANDS; n++)
  150.     inithand(n);
  151.  
  152. srand(time((long *) 0));
  153. while (TRUE)
  154.     {
  155.     clearok(stdscr, TRUE);
  156.     refresh();
  157.     for (i = 0; i < Hands; i++)
  158.         disphand(i);
  159.     wstandout(Hand[DEALER].win);
  160.     mvwprintw(Hand[DEALER].win, 0, 1, " B L A C K J A C K ");
  161.     wstandend(Hand[DEALER].win);
  162.     wprintw(Hand[DEALER].win, " by clt2!jjr... (press DEL to quit)");
  163.     mvwprintw(Hand[DEALER].win, 5, 1, "Shuffle...");
  164.     wrefresh(Hand[DEALER].win);
  165.     sleep(2);
  166.     Cards = shuffle((decks = DECKS));
  167.     Cur_card = 0;
  168.     while (Cur_card < decks * 52 / 2)
  169.         {
  170.         for (i = 1;Hands > 2; Hands--, i++)
  171.             werase(Hand[i+1].win), wrefresh(Hand[i+1].win);
  172.         Hands = 2;
  173.         for (n = 1; n < Hands; n++)
  174.             {
  175.             if (!getbet(n))
  176.                 done();
  177.             Hand[n].cnt = 0;
  178.             disphand(n);
  179.             }
  180.         Hand[DEALER].cnt = 0;
  181.         disphand(DEALER);
  182.         getcard(1); getcard(DEALER);
  183.         getcard(1); getcard(DEALER);
  184.         getcard(1);
  185.         if (Hands > 2)
  186.             {
  187.             getcard(2);
  188.             getcard(2);
  189.             }
  190.         getcard(DEALER);
  191.         for (dcnt = GETCNT(DEALER), i = 1;  i < Hands; i++)
  192.             {
  193.             if ((pcnt = GETCNT(i)) > 21 || dcnt > 21)
  194.                 cmp = (pcnt > 21) ? LOSE : WIN;
  195.             else if (pcnt == dcnt)
  196.                 cmp = (bj(i)) ? BJ : PUSH;
  197.             else
  198.                 cmp = (pcnt > dcnt) ? (bj(i) ? BJ : WIN) : LOSE;
  199.             switch (cmp)
  200.                 {
  201.             case WIN:
  202.                 Hand[i].amt += Hand[i].bet;
  203.                 Hand[DEALER].amt -= Hand[i].bet;
  204.                 ptr = " WIN ";
  205.                 break;
  206.             case BJ:
  207.                 Hand[i].amt += Hand[i].bet + (Hand[i].bet / 2);
  208.                 Hand[DEALER].amt -= (Hand[i].bet + Hand[i].bet / 2);
  209.                 ptr = " WIN ";
  210.                 break;
  211.             case PUSH:
  212.                 ptr = " PUSH ";
  213.                 break;
  214.             case LOSE:
  215.                 Hand[DEALER].amt += Hand[i].bet;
  216.                 Hand[i].amt -= Hand[i].bet;
  217.                 ptr = " LOSE ";
  218.                 break;
  219.                 }
  220.             dispbet(i);
  221.             dispbet(DEALER);
  222.             wrefresh(Hand[i].win); wrefresh(Hand[0].win);
  223.             wstandout(Hand[i].win); mvwprintw(Hand[i].win, 2, 20, ptr);
  224.             wstandend(Hand[i].win); wrefresh(Hand[i].win);
  225.             }
  226.         }
  227.     promptfor("New deck...press return to continue...", ptr, 1, "", CLR_FLD);
  228.     }
  229. }
  230. void
  231. inithand(n)
  232. short   n;
  233. {
  234.  
  235. Hand[n].win = newwin((n == DEALER) ? 7 : 5,0,(n == DEALER) ? 0 : n * 5 + 2, 0);
  236. Hand[n].amt = (DEALER == n ) ? 0 : 1000;
  237. Hand[n].bet = 0L;
  238. Hand[n].cnt = 0;
  239. strcpy(Hand[n].name, getlogin());
  240. strcpy(Hand[DEALER].name, "Dealer");
  241. }
  242. /*******************************************************************************
  243. * shuffle will return a static pointer to an array of random shorts with a range
  244. * of 0 to 52 * 'decks'. If 'decks' is > 10, then 10 decks will be returned.
  245. * If 'decks' is < 1 then one shuffled deck will be returned.
  246. */
  247. short   *
  248. shuffle(decks)
  249. short   decks;
  250. {
  251. static  short   deck[52 * 10 + 1];
  252.         short   mark[52 * 10 + 1];
  253.         short   card;
  254.         short   cnt = 0;
  255.  
  256. memset(mark, '\0', sizeof(mark));
  257. memset(deck, '\0', sizeof(deck));
  258.  
  259. decks = (decks < 1) ? 1 : ((decks > 10) ? 10 : decks);
  260. while (cnt < 52 * decks)
  261.     if ((card = (short) rand() % (52 * decks)) >= 0 && !mark[card])
  262.         deck[cnt++] = card, mark[card] = 1;
  263. deck[cnt] = -1;
  264. return(deck);
  265. }
  266. /******************************************************************************
  267. * cardtype will return a 3 character string that specifies which card 'card'
  268. * represents. Character [1] of the returned string specifies the cardinality
  269. * of 'card' and character [2] specifies the suit of 'card'.
  270. */
  271. char *
  272. cardtype(card)
  273. short   card;
  274. {
  275. static  char    value[27] = " A 2 3 4 5 6 7 8 910 J Q K";
  276. static  char    suit[4] = "SHCD";
  277. static  char    type[4];
  278.  
  279. strncpy(type, &value[((card % 52) / 4) << 1], 2);
  280. type[2] = suit[card & 3];
  281. type[3] = 0;
  282. return(type);
  283. }
  284.  
  285. int
  286. boxit(win, rows, cols, brow, bcol)
  287. WINDOW  *win;
  288. short   rows;
  289. short   cols;
  290. short   brow;
  291. short   bcol;
  292. {
  293.     short   i;
  294.  
  295. wrefresh(win);
  296. wattron(win, A_ALTCHARSET);
  297. mvwaddch(win, brow, bcol, ACS_ULCORNER);
  298. mvwaddch(win, brow+rows-1, bcol, ACS_LLCORNER);
  299. for (i=bcol+1; i < bcol+cols-1; i++)
  300.     {
  301.     mvwaddch(win, brow, i, ACS_HLINE);
  302.     mvwaddch(win, brow+rows-1, i, ACS_HLINE);
  303.     }
  304. mvwaddch(win, brow, i, ACS_URCORNER);
  305. mvwaddch(win, brow+rows-1, i, ACS_LRCORNER);
  306. for (i=brow+1; i < rows-1; i++)
  307.     {
  308.     mvwaddch(win, i, bcol, ACS_VLINE);
  309.     mvwprintw(win, i, bcol+1, "%*.*s", cols-2, cols-2, "");
  310.     mvwaddch(win, i, bcol+cols-1, ACS_VLINE);
  311.     }
  312. wrefresh(win);
  313. wattroff(win, A_ALTCHARSET);
  314. }
  315.  
  316. void
  317. getcard(hand)
  318. short   hand;
  319. {
  320.     char    c, getact();
  321.     char    *sel, *cardtype();
  322.     char    ctype1[5], ctype2[5];
  323.     short   getcard();
  324.     void    dispcard();
  325.     void    dispbet();
  326.  
  327. if (Hand[hand].cnt < 2)
  328.     {
  329.     Hand[hand].cards[Hand[hand].cnt++] = nextcard();
  330.     dispcard(hand, Hand[hand].cnt-1, (hand==DEALER&&Hand[0].cnt==2)?DOWN:UP);
  331.  
  332.     return;
  333.     }
  334. if (hand == DEALER)
  335.     {
  336.     dispcard(DEALER, 1, UP);
  337.     while (GETCNT(DEALER) < 17 || getcnt(DEALER) < 0 && GETCNT(DEALER) == 17)
  338.         {
  339.         Hand[DEALER].cards[Hand[DEALER].cnt++] = nextcard();
  340.         dispcard(DEALER, Hand[DEALER].cnt-1, UP);
  341.         }
  342.     return;
  343.     }
  344. if (GETCNT(hand) == 21)
  345.     return;
  346. strcpy(ctype1, cardtype(Hand[hand].cards[0]));
  347. strcpy(ctype2, cardtype(Hand[hand].cards[1]));
  348. sel = (Hands < MAX_HANDS && ctype1[1]==ctype2[1]) ? "HSDP0123 " : "HSD123 ";
  349. if ((c = getact(hand, sel)) == 'S')
  350.     return;
  351. if (c == 'P')
  352.     {
  353.     Hands++;
  354.     Hand[hand].cnt--;
  355.     Hand[hand+1].bet = Hand[hand].bet;
  356.     Hand[hand+1].cards[0] = Hand[hand].cards[1];
  357.     Hand[hand+1].cnt = 1;
  358.     Hand[hand+1].bet = Hand[hand].bet;
  359.     Hand[hand+1].amt = 0L;
  360.     dispbet(hand);
  361.     disphand(hand + 1);
  362.     dispcard(hand + 1, 0, UP);
  363.     }
  364. Hand[hand].cards[Hand[hand].cnt++] = nextcard();
  365. dispcard(hand, Hand[hand].cnt-1, UP);
  366. /*
  367. if (GETCNT(hand) >= 21)
  368.     return;
  369. */
  370. if (c == 'P')
  371.     {
  372.     if (getact(hand, "^HSD123 ") == 'S')
  373.         return;
  374.     Hand[hand].cards[Hand[hand].cnt++] = nextcard();
  375.     dispcard(hand, Hand[hand].cnt-1, UP);
  376.     }
  377. if (c == 'D')
  378.     {
  379.     Hand[hand].bet *= 2;
  380.     dispbet(hand);
  381.     dispbet(DEALER);
  382.     return;
  383.     }
  384.  
  385. while (GETCNT(hand) < 21)
  386.     {
  387.     if ((c=getact(hand, "^HS12 ")) == 'S')
  388.         return;
  389.     Hand[hand].cards[Hand[hand].cnt++] = nextcard();
  390.     dispcard(hand, Hand[hand].cnt-1, UP);
  391.     }
  392. return;
  393. }
  394.  
  395. short
  396. getcnt(hand)
  397. short   hand;
  398. {
  399.     char    *type;
  400.     char    *strchr();
  401.     short   cnt, acecnt;
  402.     short   i;
  403.  
  404. for (i = 0, cnt = acecnt = 0; i < Hand[hand].cnt; i++)
  405.     {
  406.     type = cardtype(Hand[hand].cards[i]);
  407.     if (strchr("KQJ0", type[1]))
  408.         cnt += 10;
  409.     else if (strchr("23456789", type[1]))
  410.         cnt += type[1] - '0';
  411.     else
  412.         cnt += 11, acecnt++;
  413.     }
  414. while (acecnt--)
  415.     if (cnt > 21)
  416.         cnt -= 10;
  417. return(acecnt>0 ? -cnt : cnt);
  418. }
  419.  
  420. char
  421. getact(hand, valact)
  422. short   hand;
  423. char    *valact;
  424. {
  425.     char    prompt[80];
  426.     char    choice[2];
  427.     char    sel[5];
  428.  
  429. strcpy(sel, "PHSD");
  430. sprintf(prompt, "Enter choice %s (Hit, Stand", Hand[hand].name);
  431. if (strchr(valact, 'D'))
  432.     strcat(prompt, ", Double");
  433. if (strchr(valact, 'P'))
  434.     strcat(prompt, ", sPlit");
  435. strcat(prompt, "): ");
  436. strcpy(choice, "S");
  437. promptfor(prompt, choice, 1, valact, MAP_UPPER|AUTO_RET);
  438. if (strchr("0123", choice[0]))
  439.     choice[0] = sel[choice[0] - '0'];
  440. return(choice[0]);
  441. }
  442.  
  443. short
  444. getbet(hand)
  445. short   hand;
  446. {
  447.     char    prompt[80];
  448.     char    bet[9];
  449.     int     atoi();
  450.  
  451. if (Hand[hand].bet > 500)
  452.     Hand[hand].bet = 500;
  453. sprintf(prompt, "Enter bet %s: ($2 - $500, 0 to quit) ", Hand[hand].name);
  454. do
  455.     {
  456.     sprintf(bet, "%hd", Hand[hand].bet);
  457.     promptfor(prompt, bet, 5, "0123456789", INIT_ONKEY);
  458.     Hand[hand].bet = (long)atoi(bet);
  459.     if (!Hand[hand].bet)
  460.         return((short) 0);
  461.     } while (Hand[hand].bet % 2 || Hand[hand].bet > 500);
  462. dispbet(hand);
  463. return(Hand[hand].bet);
  464. }
  465.  
  466. long
  467. dispbet(hand)
  468. short   hand;
  469. {
  470.     short   i;
  471.  
  472. if (hand == DEALER)
  473.     for (i = 1, Hand[DEALER].bet = 0; i < Hands; i++)
  474.         Hand[DEALER].bet += Hand[i].bet;
  475.  
  476. mvwprintw(Hand[hand].win,2,1,"stakes    : %5hd", Hand[hand].bet);
  477. mvwprintw(Hand[hand].win,3,1,"credit    : %+5hd", Hand[hand].amt);
  478. wrefresh(Hand[hand].win);
  479. return(Hand[hand].bet);
  480. }
  481.  
  482. void
  483. dispcard(hand, card, up)
  484. short   hand;
  485. short   card;
  486. short   up;
  487. {
  488.     short   bcol, val;
  489.     short   bj();
  490.     char    c,type[5];
  491.  
  492. bcol = 40 + (card - 2) * 3;
  493. wstandout(Hand[hand].win);
  494. boxit(Hand[hand].win, (short) 5, (short) 5, (short) 0, (short) bcol);
  495. if (up)
  496.     {
  497.     strcpy(type, cardtype(Hand[hand].cards[card]));
  498.     c = type[2]; type[2] = 0;
  499.     mvwprintw(Hand[hand].win, 1, bcol+1, &type[(type[0] == ' ') ? 1 : 0]);
  500.     mvwprintw(Hand[hand].win, 2, bcol+2, "%c", c);
  501.     mvwprintw(Hand[hand].win, 3, bcol+2, type);
  502.     wrefresh(Hand[hand].win);
  503.     wstandend(Hand[hand].win);
  504.     wrefresh(Hand[hand].win);
  505.     mvwprintw(Hand[hand].win, 1, 13, "%5hd", (val = GETCNT(hand)));
  506.     if (GETCNT(hand) > 21)
  507.         mvwprintw(Hand[hand].win, 1, 21, "BUST ");
  508.     if (bj(hand))
  509.         mvwprintw(Hand[hand].win, 1, 21, "BLACKJACK! ");
  510.     }
  511. wstandend(Hand[hand].win);
  512.  
  513. wrefresh(Hand[hand].win);
  514. }
  515.  
  516. void
  517. disphand(hand)
  518. short   hand;
  519. {
  520.     short   i;
  521. for (i = 0; i < 5; i++)
  522.     wmove(Hand[hand].win, i, 1), wclrtoeol(Hand[hand].win);
  523. mvwprintw(Hand[hand].win, 1, 1, "%-10.10s: ", Hand[hand].name);
  524. if (hand < 2)
  525.     dispbet(hand);
  526. wrefresh(Hand[hand].win);
  527. }
  528.  
  529. void
  530. promptfor(prompt, input, max, vchrs, flags)
  531. char    *prompt;
  532. char    *input;
  533. short   max;
  534. long    flags;
  535. {
  536.     char    *strchr();
  537. wmove(Hand[DEALER].win, 5, 1);
  538. while (*prompt)
  539.     if (strchr(vchrs, *prompt) && *prompt != ' ')
  540.         {
  541.         wstandout(Hand[DEALER].win);
  542.         waddch(Hand[DEALER].win, *prompt++);
  543.         wstandend(Hand[DEALER].win);
  544.         }
  545.     else
  546.         waddch(Hand[DEALER].win, *prompt++);
  547. waddch(Hand[DEALER].win, ' ');
  548.  
  549. get_str(Hand[DEALER].win, input, max, vchrs, flags);
  550. wmove(Hand[DEALER].win, 5, 1); wclrtoeol(Hand[DEALER].win);
  551. wrefresh(Hand[DEALER].win);
  552. }
  553.  
  554. short
  555. nextcard()
  556. {
  557. return(Cards[Cur_card++]);
  558. }
  559.  
  560. short
  561. bj(hand)
  562. short   hand;
  563. {
  564. if (GETCNT(hand) != 21)
  565.     return((short)0);
  566. if (Hand[hand].cnt == 2)
  567.     return((short)1);
  568. return((short)0);
  569. }
  570. /******************************************************************************
  571. * get a string through curses...how many times has this been re-written?
  572. * Returns:      key that caused get_str to return.
  573. * Side Effects: _str_ holds a space padded array of characters entered by user.
  574. *               _win_ will be changed by the contents of string
  575. * Note: wattron before call to get_str for pretty display of input box...
  576. *       noecho() should be enabled...
  577. */
  578. short
  579. get_str(win, str, max, vchrs, flags)
  580. WINDOW  *win;           /* input window */
  581. char    *str;           /* changed by side effect   */
  582. short   max;            /* stop when this is reached    */
  583. char    *vchrs;         /* valid keystrokes...  */
  584. short   flags;          /* all kinds of options...  */
  585. {
  586.  
  587.     short   sr, sc;     /* save row save column -restored on ret*/
  588.     short   ofs =0;     /* current offset from beginning of str */
  589.     short   ret =0;     /* return status != when return desired */
  590.     short   c;          /* each input char is put into this var */
  591.     short   first=TRUE; /* first time through the main loop?    */
  592.     char    save[256];  /* max better be less than 256 chars    */
  593.  
  594. wrefresh(win);                          /* dump any changes */
  595. getyx(win, sr, sc);                     /* get logical cursor location*/
  596. if (flags & CLR_FLD)                    /* initialize field from beginning? */
  597.     sprintf(str, "%*.*s", max, max, "");
  598. strcpy(save, str);                      /* save in case of an ESC...    */
  599. sprintf(str, "%-*.*s", max, max, save); /* left justified...pad for now...  */
  600. if (~flags & NOECHO)                    /* if we want to echo string... */
  601.     waddstr(win, str);
  602. wmove(win, sr, sc+ofs);
  603. while (!ret)
  604.     {
  605.     if (isprint((c = get_chr(win, vchrs, flags))))
  606.         {                               /* clear the input string on first  */
  607.         if (ofs == max)                 /* dont write over the terminating  */
  608.             ofs--;                      /* null character...                */
  609.         if (first && flags & INIT_ONKEY)/* clear on first printable char... */
  610.             sprintf(str, "%*.*s", max, max, "");
  611.         str[ofs++] = (char) c;
  612.         if (ofs == max)                 /* if at end of string already...   */
  613.             if (flags & AUTO_RET)       /*   and AUTO_RET flag ON then...   */
  614.                 ret = CR;               /*     pretend CR was pressed...    */
  615.         }
  616.     else
  617.         switch (c)
  618.             {
  619.         case CR:
  620.         case NL:
  621.         case KEY_UP:
  622.         case KEY_DOWN:
  623.             ret = c;
  624.             break;
  625.         case ESC:
  626.             strcpy(str, save);
  627.             ret = c;
  628.             break;
  629.         case KEY_RIGHT:
  630.             if (ofs < max)
  631.                 str[ofs++] = ' ';
  632.             break;
  633.         case KEY_LEFT:
  634.         case BS:
  635.             if (ofs)
  636.                 ofs--;
  637.             break;
  638.         default:
  639.             ret = c;
  640.             break;
  641.             }
  642.     if (~flags & NOECHO)                /* if NOECHO is OFF then disp str...*/
  643.         mvwaddstr(win, sr, sc, str);    /* (display after each character)   */
  644.     wmove(win, sr, sc+ofs);
  645.     wrefresh(win);
  646.     first = FALSE;                      /* we have been around the loop...  */
  647.     }
  648. if (flags & NOPAD)
  649.     for (ofs = 0; ofs < max; ofs++)
  650.         if (str[ofs] == ' ')
  651.             c = ofs;
  652. return(ret);
  653. }
  654.  
  655. short
  656. get_chr(win, vchrs, flags)
  657. WINDOW  *win;
  658. char    *vchrs;
  659. short   flags;
  660. {
  661.     short   c;
  662. wrefresh(win);
  663. while ((c = wgetch(win)) == ERR)
  664.     if (isprint(c) && strchr(vchrs, c))
  665.         break;
  666.     else if (flags & BEEP)
  667.         beep();
  668. if (flags & MAP_UPPER)
  669.     if (c >= 'a' && c <= 'z')
  670.         c = toupper(c);
  671. if (flags & MAP_LOWER)
  672.     if (c >= 'A' && c <= 'A')
  673.         c = tolower(c);
  674. return(c);
  675.  
  676. }
  677.  
  678. void
  679. done()
  680. {
  681. mvprintw(19, 20, "Quit with %hd dollars",  Hand[1].amt);
  682. mvprintw(20, 20, "Press any key to exit...");
  683. refresh();
  684. getch();
  685.  
  686. endwin();
  687. exit(0);
  688. }
  689. ---cut here---cut here---cut here---cut here---cut here---cut here---cut here--
  690.  
  691. -- 
  692.  .--------------------------.  ...  |On the border of your mind lies a place
  693.  |uunet!mcnc!unccvax!cs00chs|  (")  |where dreams and reality are one...I will 
  694.  `--------------------------'-w-U-w-|take you there, for I am the subject...
  695.  \%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\|the subject of your imagination. -Aldo Nova
  696.