home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3431 / draw.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-28  |  2.9 KB  |  119 lines

  1. /*LINTLIBRARY*/
  2.  
  3. /*
  4.  * Copyright (C) 1991 by Jay Konigsberg. mail: jak@sactoh0
  5.  *
  6.  * Permission to use, copy, modify, and distribute this  software  and  its
  7.  * documentation is hereby  granted,  provided  that  the  above  copyright
  8.  * notice appear in all copies  and that  both  the  copyright  notice  and
  9.  * this permission notice appear in supporting documentation. This software
  10.  * is provided "as is" without express or implied  warranty.  However,  the
  11.  * author retains all Copyright priviliges and rights  to  renumeration  if
  12.  * this software is sold.
  13.  *
  14.  * Also, and very important. This game is for recrecation ONLY and is NOT
  15.  * to be used for gambling in any way. 
  16.  */
  17.  
  18. /*
  19.  * draw.c - Select which card to hold (You've got to know when to hold-um, ..
  20.  */
  21.  
  22. #include    "vid_local.h"
  23. #include    "vid_curses.h"
  24. #include    "vid_poker.h"
  25. #include    "vid_extern.h"
  26.  
  27. extern    int    bet;
  28. extern    int    credits;
  29.  
  30. void    draw(deck, value, suite)
  31. int    *deck,
  32.     *value;
  33. char    **suite;
  34. {
  35. int    count,        /* count of cards to be drawn    */
  36.     index,        /* loop index            */
  37.     win,        /* amount won on hand        */
  38.     key = -1,    /* keys pressed during draw    */
  39.     draw_card=5,    /* The first draw card        */
  40.     hold[5];    /* mark the cards help        */
  41.  
  42. for (index=0; index < 5; ++index)
  43.     hold[index] = 0;
  44.  
  45. mvaddstr(21,0,"Keys 1-5 to hold/cancel cards, D/d/space/return to draw:      ");
  46. move(21,57);
  47. refresh();
  48. while ( key != ' ' && key != '\r' && key != '\n' && key != 'D' && key != 'd' )
  49.     {
  50.     /*
  51.      * XXX - the echoback needs to be shut down here to prevent misplacement
  52.      * of the "HOLD" string. However, using 'noecho()' and 'echo()' will
  53.      * force buffering of all output until a CR is read.
  54.      */
  55.     if( (key=mvgetch(21, 57)) >= '0' && key <= '5' )
  56.     {
  57.     addstr("\b ");
  58.     move(19, 4+(15 * ((key - '0')-1)));
  59.     if ( hold[(key - '0') - 1] )
  60.         {
  61.         addstr("    ");
  62.         hold[(key - '0' -1) ] = 0;
  63.         }
  64.     else
  65.         {
  66.         addstr("HOLD");
  67.         hold[ (key - '0' -1) ] = 1;
  68.         }
  69.     }
  70.     else
  71.     {
  72.     if ( key == 'r' || key == 'R' )
  73.         {
  74.         addstr(" \b ");
  75.         clearok(stdscr, TRUE);
  76.         refresh();
  77.         }
  78.     else
  79.         if ( key != '\r' && key != ' ' && key != '\n' &&
  80.         key != 'D' && key != 'd' && key != 'R' && key != 'r' )
  81.         {
  82.         putchar('\007');
  83.         fflush(stdout);
  84.         }
  85.     }
  86.     refresh();
  87.     }
  88.  
  89. /* cards selected, now draw */
  90. count=0;
  91. for(index=0; index < 5; ++index)
  92.     if ( hold[index] )
  93.     ++count;
  94. count = 5 - count;
  95.  
  96. deal(deck, count);
  97. setup_deck(deck, value, suite, count);
  98.  
  99. /* Replace the discarded cards */
  100. for( index=0; index < 5 && count; ++index )
  101.     {
  102.     if ( hold[index] == 0 )        /* card NOT held */
  103.     {
  104.     draw_back(index);
  105.     value[index] = value[draw_card];
  106.     suite[index] = suite[draw_card++];
  107.     --count;
  108.     }
  109.     }
  110. sleep(1);
  111. display_hand(value, suite, 5);
  112. sort(value, suite, 5);
  113. win = bet * display_val(id_hand(value, suite));
  114. credits += win;
  115. mvprintw(22, 65, "Credits %-6d     ", credits);
  116. mvprintw(23, 65, "Winner  %-6d     ", win);
  117. refresh();
  118. }
  119.