home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3281 / draw.c < prev    next >
C/C++ Source or Header  |  1991-05-02  |  2KB  |  101 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.  
  26. extern    int    bet;
  27. extern    int    credits;
  28.  
  29. void    draw(deck, value, suite)
  30. int    *deck,
  31.     *value;
  32. char    **suite;
  33. {
  34. int    count,        /* count of cards to be drawn    */
  35.     index,        /* loop index            */
  36.     win,        /* amount won on hand        */
  37.     key = -1,    /* keys pressed during draw    */
  38.     draw_card=5,    /* The first draw card        */
  39.     hold[5];    /* mark the cards help        */
  40.  
  41. for (index=0; index < 5; ++index)
  42.     hold[index] = 0;
  43.  
  44. mvaddstr(19, 0, "\t\t\t\t\t\t\t\t\t\t");
  45. mvaddstr(21, 0, "Keys 1-5 will hold/cancel cards, space/return to draw:");
  46. refresh();
  47. while ( key != ' ' && key != '\r' )
  48.     {
  49.     if( (key=mvgetch(21,56)) >= '0' && key <= '5' )
  50.     {
  51.     addstr("\010 ");
  52.     move(19, 4+(15 * ((key - '0')-1)));
  53.     if ( hold[(key - '0') - 1] )
  54.         {
  55.         addstr("    ");
  56.         hold[(key - '0' -1) ] = 0;
  57.         }
  58.     else
  59.         {
  60.         addstr("HOLD");
  61.         hold[ (key - '0' -1) ] = 1;
  62.         }
  63.     }
  64.     else
  65.     if ( key != '\r' && key != ' ' )
  66.     {
  67.     putchar('\007');
  68.     fflush(stdout);
  69.     }
  70.     refresh();
  71.     }
  72.  
  73. /* cards selected, now draw */
  74. count=0;
  75. for(index=0; index < 5; ++index)
  76.     if ( hold[index] )
  77.     ++count;
  78. count = 5 - count;
  79.  
  80. deal(deck, count);
  81. setup_deck(deck, value, suite, count);
  82.  
  83. /* Replace the discarded cards */
  84. for( index=0; index < 5 && count; ++index )
  85.     {
  86.     if ( hold[index] == 0 )        /* card NOT held */
  87.     {
  88.     value[index] = value[draw_card];
  89.     suite[index] = suite[draw_card++];
  90.     --count;
  91.     }
  92.     }
  93. display_hand(value, suite, 5);
  94. sort(value, suite, 5);
  95. win = bet * display_val(id_hand(value, suite));
  96. credits += win;
  97. mvprintw(22, 65, "Credits %-6d     ", credits);
  98. mvprintw(23, 65, "Winner  %-6d     ", win);
  99. refresh();
  100. }
  101.