home *** CD-ROM | disk | FTP | other *** search
/ Media Share 13 / mediashare_13.zip / mediashare_13 / ZIPPED / PROGRAM / WTJ9403.ZIP / POKER / POKERVW.CPP < prev    next >
C/C++ Source or Header  |  1994-01-31  |  22KB  |  960 lines

  1. // pokervw.cpp : implementation of the CPokerView class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "poker.h"
  6.  
  7. #include "pokerdoc.h"
  8. #include "pokervw.h"
  9. #include "betdlg.h"
  10.  
  11. #include "cardback.h"
  12.  
  13. #include <time.h>
  14.  
  15.  
  16. #ifdef _DEBUG
  17. #undef THIS_FILE
  18. static char BASED_CODE THIS_FILE[] = __FILE__;
  19. #endif
  20.  
  21. int    what1 = 0;
  22. int    what2 = 0;
  23.  
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CPokerView
  26.  
  27. IMPLEMENT_DYNCREATE(CPokerView, CView)
  28.  
  29. BEGIN_MESSAGE_MAP(CPokerView, CView)
  30.     //{{AFX_MSG_MAP(CPokerView)
  31.     ON_WM_TIMER()
  32.     ON_WM_CREATE()
  33.     ON_COMMAND(ID_VIEW_CHANGECARDBACKS, OnViewChangecardbacks)
  34.     ON_WM_SIZE()
  35.     ON_WM_DESTROY()
  36.     ON_WM_LBUTTONUP()
  37.     ON_COMMAND(ID_FILE_NEWGAME, OnFileNewgame)
  38.     ON_WM_LBUTTONDOWN()
  39.     ON_UPDATE_COMMAND_UI(ID_MOVES_BET, OnUpdateMovesBet)
  40.     ON_UPDATE_COMMAND_UI(ID_MOVES_CALL, OnUpdateMovesCall)
  41.     ON_UPDATE_COMMAND_UI(ID_MOVES_CHECK, OnUpdateMovesCheck)
  42.     ON_UPDATE_COMMAND_UI(ID_MOVES_FOLD, OnUpdateMovesFold)
  43.     ON_UPDATE_COMMAND_UI(ID_MOVES_RAISE, OnUpdateMovesRaise)
  44.     ON_COMMAND(ID_MOVES_BET, OnMovesBet)
  45.     ON_UPDATE_COMMAND_UI(ID_MOVES_DEAL, OnUpdateMovesDeal)
  46.     ON_COMMAND(ID_MOVES_DEAL, OnMovesDeal)
  47.     ON_COMMAND(ID_MOVES_CALL, OnMovesCall)
  48.     ON_COMMAND(ID_MOVES_FOLD, OnMovesFold)
  49.     ON_COMMAND(ID_MOVES_RAISE, OnMovesRaise)
  50.     //}}AFX_MSG_MAP
  51.     // Standard printing commands
  52.     ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
  53.     ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
  54. END_MESSAGE_MAP()
  55.  
  56. /////////////////////////////////////////////////////////////////////////////
  57. // CPokerView construction/destruction
  58.  
  59. CPokerView::CPokerView()
  60. {
  61.     // TODO: add construction code here
  62. }
  63.            
  64. CPokerView::~CPokerView()
  65. {
  66.     CPokerDoc* pDoc = GetDocument();
  67.     KillTimer(pDoc->nTimer);
  68. }
  69.  
  70. /////////////////////////////////////////////////////////////////////////////
  71. // CPokerView drawing
  72.  
  73. void CPokerView::OnDraw(CDC* pDC)
  74. {   
  75. COLORREF    Color = 0x00FFFFFF;
  76. int        i;
  77. int        j;
  78.  
  79.     CPokerDoc* pDoc = GetDocument();
  80.     
  81.     for (i = 0; i < NUMBER_PLAYERS; i++)
  82.     {
  83.         for (j = 0; j < 5; j++)
  84.         {
  85.             CDTDraw(pDC->GetSafeHdc(), 
  86.                 pDoc->CardLocation[i][j].x, 
  87.                 pDoc->CardLocation[i][j].y, 
  88.                 PlayerCard(i, j), 
  89.                 CardDrawMode(i, j), 
  90.                 Color);
  91.         }
  92.     }                      
  93. }
  94.  
  95. void CPokerView::DrawOnePlayer(CClientDC* pDC, int nPlayer)
  96. {   
  97. COLORREF    Color = 0x00FFFFFF;
  98. int        j;
  99.  
  100.     CPokerDoc* pDoc = GetDocument();
  101.     
  102.     for (j = 0; j < 5; j++)
  103.     {
  104.         CDTDraw(pDC->GetSafeHdc(), 
  105.             pDoc->CardLocation[nPlayer][j].x, 
  106.             pDoc->CardLocation[nPlayer][j].y, 
  107.             PlayerCard(nPlayer, j), 
  108.             CardDrawMode(nPlayer, j), 
  109.             Color);
  110.     }
  111. }
  112.  
  113. CPokerView::PlayerCard(int    nPlayer, int nCard)
  114. {               
  115.     CPokerDoc* pDoc = GetDocument();
  116.     
  117. //    For debugging, uncomment the following line (also see CardDrawMode, below):
  118. //    return(pDoc->nHand[nPlayer][nCard]);
  119.  
  120. // For real play, use the following lines:
  121.  
  122.      if (pDoc->bFace[nPlayer] || 
  123.          nPlayer == ME || 
  124.          pDoc->nGameState == SHOWDOWN || 
  125.          pDoc->nGameState == WAIT) 
  126.      {
  127.          return(pDoc->nHand[nPlayer][nCard]);
  128.      }
  129.      else
  130.      {
  131.          return(pDoc->nCurrentBack);
  132.      }
  133. }
  134.  
  135. CPokerView::CardDrawMode(int nPlayer, int nCard)
  136. {                            
  137. //    For debugging uncomment the following line (also see PlayerCard, above):
  138. //    return(DRAW_FACES);
  139.  
  140. //  For normal operation, use this code:
  141.  
  142.     CPokerDoc* pDoc = GetDocument();
  143.     if (nPlayer == ME && pDoc->nCardState[nPlayer][nCard] == CARD_INVERT)
  144.     {
  145.         return(pDoc->nCardState[nPlayer][nCard]);
  146.     }
  147.  
  148.     if (pDoc->nPlayerAction[nPlayer] == FOLD)
  149.     {
  150.         return(CARD_FOLD);
  151.     }
  152.  
  153.     if (pDoc->nCardState[nPlayer][nCard] == CARD_INVERT || 
  154.         pDoc->nCardState[nPlayer][nCard] == CARD_DISCARD)
  155.     {
  156.         return(CARD_DISCARD);
  157.     }
  158.  
  159.      if (pDoc->bFace[nPlayer] || nPlayer == ME)
  160.      {
  161.          return(DRAW_FACES);
  162.      }
  163.      else
  164.      {
  165.          return(DRAW_BACKS);
  166.      }
  167. }
  168.  
  169. /////////////////////////////////////////////////////////////////////////////
  170. // CPokerView printing
  171.  
  172. BOOL CPokerView::OnPreparePrinting(CPrintInfo* pInfo)
  173. {
  174.     // default preparation
  175.     return DoPreparePrinting(pInfo);
  176. }
  177.  
  178. void CPokerView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  179. {
  180.     // TODO: add extra initialization before printing
  181. }
  182.  
  183. void CPokerView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  184. {
  185.     // TODO: add cleanup after printing
  186. }
  187.  
  188. /////////////////////////////////////////////////////////////////////////////
  189. // CPokerView diagnostics
  190.  
  191. #ifdef _DEBUG
  192. void CPokerView::AssertValid() const
  193. {
  194.     CView::AssertValid();
  195. }
  196.  
  197. void CPokerView::Dump(CDumpContext& dc) const
  198. {
  199.     CView::Dump(dc);
  200. }
  201.  
  202. CPokerDoc* CPokerView::GetDocument() // non-debug version is inline
  203. {
  204.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CPokerDoc)));
  205.     return (CPokerDoc*) m_pDocument;
  206. }
  207.  
  208. #endif //_DEBUG
  209.  
  210. /////////////////////////////////////////////////////////////////////////////
  211. // CPokerView message handlers
  212.  
  213.  
  214. void CPokerView::OnTimer(UINT nIDEvent)
  215. {       
  216.     CPokerDoc* pDoc = GetDocument();
  217.  
  218.     if (pDoc->nAnimationCounter <= 0 && // We're (over)due for back animation.
  219.          pDoc->nGameState != SHOWDOWN && // Don't animate showdown or wait 
  220.          pDoc->nGameState != WAIT      && // because card faces are being shown...
  221.          pDoc->nPlayerAction[DEALER] != FOLD)
  222.     {// We are in the middle of an animation sequence
  223.         OnAnimate();
  224.         if (++pDoc->nBackAnimate > 4)
  225.         {
  226.             pDoc->nBackAnimate = 0;
  227.             pDoc->nAnimationCounter = rand() % 25;
  228.  
  229.             if (pDoc->nAnimationCounter < 6)
  230.                 pDoc->nAnimationCounter += 6;            
  231.         }    
  232.     }
  233.     else
  234.     {
  235.         --pDoc->nAnimationCounter;
  236.     }
  237.     
  238. //  Next, we perform a player's move, if there are any...
  239.     switch(pDoc->nGameState)
  240.     {
  241.         case DEAL:
  242.             pDoc->Deal();
  243.             break;
  244.         
  245.         case FIRST_ROUND:
  246.             Play(pDoc->nCurrentPlayer);            
  247.             break;
  248.         
  249.         case DRAW_SELECT:
  250.             DrawSelect(pDoc->nCurrentPlayer);
  251.             break;
  252.             
  253.         case DRAW_DISCARD:
  254.             DrawDiscard(pDoc->nCurrentPlayer);
  255.             break;
  256.             
  257.         case DRAW_DEAL:
  258.             DrawDeal(pDoc->nCurrentPlayer);
  259.             break;
  260.             
  261.         case SECOND_ROUND:
  262.             Play(pDoc->nCurrentPlayer);
  263.             break;
  264.             
  265.         case SHOWDOWN:
  266.             Showdown(pDoc->nCurrentPlayer);
  267.             break;
  268.             
  269.         case WAIT:
  270.             break;
  271.     }
  272.  
  273. //  Finally, update the game's state, if appropriate:
  274.  
  275.     pDoc->UpdateGameState();
  276.     
  277. //    and in the end: call default handler, then return.
  278.     
  279.     CView::OnTimer(nIDEvent);
  280. }
  281.  
  282. void     CPokerView::DrawSelect(int nPlayer)
  283. {// For now, each player (except for me) will keep his cards.
  284.     if (nPlayer != ME)
  285.     {
  286.         TRACE("Player %d being delt his DRAW cards\n", nPlayer);
  287.         CPokerDoc* pDoc = GetDocument();
  288. //        Discard two cards at random...        
  289. //        A final version would discard cards based on a strategy...
  290.  
  291.         pDoc->nCardState[nPlayer][0] = CARD_INVERT;
  292.         pDoc->nCardState[nPlayer][3] = CARD_INVERT;
  293.  
  294. //        Checking is a gutless move, with a strategy,
  295. //        a player would bet, fold or whatever:
  296.         pDoc->nPlayerAction[nPlayer] = CHECK;    
  297.         pDoc->NextPlayer();
  298.     }
  299. }
  300.  
  301. void     CPokerView::DrawDiscard(int nPlayer)
  302. {// For now, each player delete cards (from window) that were discarded.
  303. int        i;
  304. int        bTookCards = FALSE;
  305.  
  306.     CPokerDoc* pDoc = GetDocument();
  307.     for (i = 0; i < 5; i++)
  308.     {
  309.         if (pDoc->nCardState[nPlayer][i] == CARD_INVERT)
  310.         {// card selected for replacement by the player
  311.             pDoc->nCardState[nPlayer][i] == CARD_DISCARD;
  312.             bTookCards = TRUE;
  313.         }
  314.     }            
  315.     
  316.     if (bTookCards)
  317.     {
  318.         CClientDC dc(this);                         
  319.         DrawOnePlayer(&dc, nPlayer);    
  320.     }
  321.  
  322.     TRACE("Player %d discarding\n", nPlayer);
  323.     pDoc->nPlayerAction[nPlayer] = CHECK;    
  324.     pDoc->NextPlayer();
  325. }
  326.  
  327. void     CPokerView::DrawDeal(int nPlayer)
  328. {// For now, each player deal & display their new cards.
  329.         TRACE("Player %d getting his new cards\n", nPlayer);
  330.         CPokerDoc* pDoc = GetDocument();
  331.         if (pDoc->DealDraw(nPlayer))
  332.         {
  333.             CClientDC dc(this);                         
  334.             DrawOnePlayer(&dc, nPlayer);    
  335.         }
  336.         pDoc->nPlayerAction[nPlayer] = CHECK;    
  337.         pDoc->NextPlayer();
  338. }
  339.  
  340. void     CPokerView::Showdown(int nPlayer)
  341. {// Show each player's cards. Do it in a block?
  342.     CPokerDoc* pDoc = GetDocument();
  343.     pDoc->bFace[nPlayer] = TRUE;
  344.     pDoc->nPlayerAction[nPlayer] = CHECK;    
  345.     pDoc->NextPlayer();
  346.     CClientDC dc(this);                         
  347.     DrawOnePlayer(&dc, nPlayer);    
  348. }
  349.  
  350. void    CPokerView::Play(int nPlayer)
  351. {   
  352. int        i;
  353. int        nHandPotential;
  354. int        nPlayerBet = 0;
  355. int        nFirst    = TRUE;
  356. int        nBet    = FALSE;
  357. int        nFold    = FALSE;
  358. int        nRaise    = FALSE;
  359. int        nIRaise    = FALSE;
  360. int        nIBet    = FALSE;
  361. int        nICall    = FALSE;
  362.  
  363. //    Each of the computer's hands (0, 1 and 2) must be played. The valid actions
  364. //         must be determined, and then an appropriate action must be taked.
  365. //         Pass 1: Always BET $10, don't raise, fold or check...
  366.  
  367.     CPokerDoc* pDoc = GetDocument();
  368.  
  369.     if (pDoc->nPlayerAction[nPlayer] == FOLD)
  370.     {// This player is out of the loop!
  371.         return;
  372.     }
  373.  
  374. //    Determine what action to take.
  375. //    First, am I the first to actually play.
  376.  
  377.     if (nPlayer != ME)
  378.     {
  379.         if (pDoc->nPlayerAction[nPlayer] == BET)
  380.             nIBet = TRUE;
  381.         if (pDoc->nPlayerAction[nPlayer] == FOLD)
  382.             nICall = TRUE;
  383.         if (pDoc->nPlayerAction[nPlayer] == RAISE)
  384.             nIRaise = TRUE;
  385.                  
  386.         for (i = 0; i < NUMBER_PLAYERS; i++)
  387.         {
  388.             if (i != nPlayer)
  389.             {
  390.                 if (pDoc->nPlayerAction[i] != NOTHING &&
  391.                     pDoc->nPlayerAction[i] != CHECK)
  392.                 {// This player is out of the loop!
  393.                     nFirst = FALSE;
  394.                 }
  395.                 if (pDoc->nPlayerAction[i] == BET)
  396.                 {// This player BET!
  397.                     nBet = TRUE;
  398.                 }
  399.                 if (pDoc->nPlayerAction[i] == FOLD)
  400.                 {// This player FOLDed!
  401.                     nFold = TRUE;
  402.                 }
  403.                 if (pDoc->nPlayerAction[i] == RAISE)
  404.                 {// This player FOLDed!
  405.                     nRaise = TRUE;
  406.                 }
  407.             }
  408.         }
  409.         
  410.         if (nFirst || !nBet)
  411.         {// Nobody's bet yet. This playereither BET, FOLD, or CHECK (if first)
  412.             nHandPotential = pDoc->EvaluateFirst(nPlayer);
  413.             switch(nHandPotential)
  414.             {
  415.                 case ROYAL_FLUSH        :
  416.                     pDoc->nPlayerAction[nPlayer] = BET;
  417.                     nPlayerBet = 3;
  418.                     break;
  419.                 case STRAIGHT_FLUSH        :
  420.                     pDoc->nPlayerAction[nPlayer] = BET;
  421.                     nPlayerBet = 3;
  422.                     break;
  423.                 case FOUR_OF_KIND        :
  424.                     pDoc->nPlayerAction[nPlayer] = BET;
  425.                     nPlayerBet = 3;
  426.                     break;
  427.                 case FULL_HOUSE            :
  428.                     pDoc->nPlayerAction[nPlayer] = BET;
  429.                     nPlayerBet = 3;
  430.                     break;
  431.                 case FLUSH                :
  432.                     pDoc->nPlayerAction[nPlayer] = BET;
  433.                     nPlayerBet = 3;
  434.                     break;
  435.                 case STRAIGHT            :
  436.                     pDoc->nPlayerAction[nPlayer] = BET;
  437.                     nPlayerBet = 3;
  438.                     break;
  439.                 case THREE_OF_KIND        :
  440.                     pDoc->nPlayerAction[nPlayer] = BET;
  441.                     nPlayerBet = 4;
  442.                     break;
  443.                 case TWO_PAIR            :
  444.                     pDoc->nPlayerAction[nPlayer] = BET;
  445.                     nPlayerBet = 3;
  446.                     break;
  447.                 case ONE_PAIR            :
  448.                     pDoc->nPlayerAction[nPlayer] = BET;
  449.                     nPlayerBet = 2;
  450.                     break;
  451.                 case POSSIBLE_STRAIGHT    :
  452.                     if (!nFirst) // Can't check
  453.                         pDoc->nPlayerAction[nPlayer] = FOLD;
  454.                     else
  455.                         pDoc->nPlayerAction[nPlayer] = CHECK;
  456.     
  457.                     break;
  458.                 case POSSIBLE_FLUSH        :
  459.                     if (!nFirst) // Can't check
  460.                         pDoc->nPlayerAction[nPlayer] = FOLD;
  461.                     else
  462.                         pDoc->nPlayerAction[nPlayer] = CHECK;
  463.                         
  464.                     break;
  465.                 case GOT_SQUAT            :
  466.                     pDoc->nPlayerAction[nPlayer] = FOLD;
  467.                     break;
  468.                }
  469.         }
  470.         else
  471.         {// Just playing along, can either FOLD, CALL, or RAISE
  472.             nHandPotential = pDoc->EvaluateFirst(nPlayer);
  473.             switch(nHandPotential)
  474.             {
  475.                 case ROYAL_FLUSH        :
  476.                     if (nIBet && !nRaise) // Can't raise if I bet and another player didn't raise
  477.                     {
  478.                         pDoc->nPlayerAction[nPlayer] = CALL;
  479.                     }
  480.                     else
  481.                     {
  482.                         pDoc->nPlayerAction[nPlayer] = RAISE;
  483.                         nPlayerBet = 4;
  484.                     }
  485.                     break;
  486.                 case STRAIGHT_FLUSH        :
  487.                     if (nIBet && !nRaise) // Can't raise if I bet and another player didn't raise
  488.                     {
  489.                         pDoc->nPlayerAction[nPlayer] = CALL;
  490.                     }
  491.                     else
  492.                     {
  493.                         pDoc->nPlayerAction[nPlayer] = RAISE;
  494.                         nPlayerBet = 5;
  495.                     }
  496.                     break;
  497.                 case FOUR_OF_KIND        :
  498.                     if (nIBet && !nRaise) // Can't raise if I bet and another player didn't raise
  499.                     {
  500.                         pDoc->nPlayerAction[nPlayer] = CALL;
  501.                     }
  502.                     else
  503.                     {
  504.                         pDoc->nPlayerAction[nPlayer] = RAISE;
  505.                         nPlayerBet = 5;
  506.                     }
  507.                     break;
  508.                 case FULL_HOUSE            :
  509.                     if (nIBet && !nRaise) // Can't raise if I bet and another player didn't raise
  510.                     {
  511.                         pDoc->nPlayerAction[nPlayer] = CALL;
  512.                     }
  513.                     else
  514.                     {
  515.                         pDoc->nPlayerAction[nPlayer] = RAISE;
  516.                         nPlayerBet = 5;
  517.                     }
  518.                     break;                          
  519.                 case FLUSH                :
  520.                     if (nIBet && !nRaise) // Can't raise if I bet and another player didn't raise
  521.                     {
  522.                         pDoc->nPlayerAction[nPlayer] = CALL;
  523.                     }
  524.                     else
  525.                     {
  526.                         pDoc->nPlayerAction[nPlayer] = RAISE;
  527.                         nPlayerBet = 4;
  528.                     }
  529.                     break;
  530.                 case STRAIGHT            :
  531.                     pDoc->nPlayerAction[nPlayer] = CALL;
  532.                     break;
  533.                 case THREE_OF_KIND        :
  534.                     pDoc->nPlayerAction[nPlayer] = CALL;
  535.                     break;
  536.                 case TWO_PAIR            :
  537.                     pDoc->nPlayerAction[nPlayer] = CALL;
  538.                     break;
  539.                 case ONE_PAIR            :
  540.                     pDoc->nPlayerAction[nPlayer] = CALL;
  541.                     break;
  542.                 case POSSIBLE_STRAIGHT    :
  543.                     pDoc->nPlayerAction[nPlayer] = CALL;
  544.                     break;
  545.                 case POSSIBLE_FLUSH        :
  546.                     pDoc->nPlayerAction[nPlayer] = CALL;
  547.                     break;
  548.                 case GOT_SQUAT            :
  549.                     pDoc->nPlayerAction[nPlayer] = FOLD;
  550.                     break;
  551.                }        
  552.         }
  553.     }
  554.     if (nPlayer != ME)
  555.     {// My plays are by me.
  556.         PlayerAction(nPlayer, nPlayerBet);
  557.     }
  558. }
  559.  
  560. void CPokerView::PlayerAction(int nPlayer, int nPlayerBet)
  561. {
  562.     TRACE("GETTING THE DOCUMENT>>>>>>>>>>>>\n");
  563.     CPokerDoc* pDoc = GetDocument();
  564.  
  565.     switch(pDoc->nPlayerAction[nPlayer])
  566.     {
  567.          case BET:
  568.             pDoc->Bet(nPlayer, nPlayerBet);
  569.              break;
  570.          case CALL:
  571.             pDoc->Call(nPlayer);
  572.              break;
  573.          case FOLD:
  574.              {
  575.                 pDoc->Fold(nPlayer);
  576.                 CClientDC dc(this);                         
  577.                 DrawOnePlayer(&dc, nPlayer);    
  578.             }
  579.             break;
  580.          case RAISE:
  581.             pDoc->Raise(nPlayer, nPlayerBet);
  582.              break;
  583.          case CHECK:
  584.             pDoc->Check(nPlayer);
  585.              break;
  586.          default:
  587.              TRACE("INVALID: action by a player\n");
  588.              break;
  589.     }
  590.     pDoc->NextPlayer();
  591. }
  592.  
  593. void CPokerView::OnAnimate()
  594. {// happens when the backs are to be animated.
  595. int        nReturn;
  596.  
  597.     CPokerDoc* pDoc = GetDocument();
  598.  
  599.     if (pDoc->nBackAnimate == 0)
  600.     {// Pick a card to animate
  601.         pDoc->nAnimateCard = rand() % 4;
  602.     }
  603.     
  604.     CClientDC dc(this);                         
  605.  
  606.     nReturn = CDTAnimate(dc.GetSafeHdc(), 
  607.         pDoc->nCurrentBack, 
  608.         pDoc->CardLocation[1][pDoc->nAnimateCard].x, 
  609.         pDoc->CardLocation[1][pDoc->nAnimateCard].y, 
  610.         pDoc->nBackAnimate);
  611. }
  612.  
  613.  
  614.  
  615. int CPokerView::OnCreate(LPCREATESTRUCT lpCreateStruct)
  616. {
  617.     if (CView::OnCreate(lpCreateStruct) == -1)
  618.         return -1;
  619.  
  620.     CPokerDoc* pDoc = GetDocument();
  621.     
  622. /*    We use the timer to control the following things:
  623.  *
  624.  *    1. Some of the card backs are capable of animation. These include the hand 
  625.  *         holding cards, sun, robot and castle backs. We install a timer, set it to 
  626.  *        four tenth's of a second and when timer goes off, we decrement the back animation
  627.  *      counter. When this timer is == 0, we animate a random card belonging to the 
  628.  *      dealer. As well, after we start animating the card, 
  629.  *        we countdown the animation, and then set a new back animation timer value. 
  630.  */
  631.    
  632.     pDoc->nTimer = SetTimer(9, 400, NULL);   
  633.  
  634.     if (pDoc->nTimer == 0)
  635.     {// Couldn't set the timer. Bummer, no game today...
  636.         TRACE("Couldn't set the timer. Bummer, no game today...\n");
  637.         // END THE PROGRAM HERE!        
  638.     }
  639.     
  640.     // TODO: Add your specialized creation code here
  641.     
  642.     return 0;
  643. }
  644.  
  645. void CPokerView::OnViewChangecardbacks()
  646. {
  647. CCardBack Dialog;
  648.  
  649.     CPokerDoc* pDoc = GetDocument();
  650.     Dialog.m_nCardBack = pDoc->nCurrentBack;
  651.     Dialog.DoModal();
  652.     if (Dialog.m_nCardBack != pDoc->nCurrentBack)
  653.     {// The user selected a new back!
  654.          pDoc->nCurrentBack  = Dialog.m_nCardBack;
  655.         CClientDC dc(this);                         
  656.          InvalidateRect(NULL, TRUE);
  657.     }
  658. }
  659.  
  660. void CPokerView::OnSize(UINT nType, int cx, int cy)
  661. {
  662.     CView::OnSize(nType, cx, cy);
  663.     
  664.     // TODO: Add your message handler code here
  665.     TRACE("Sized with a view width of %d and height of %d\n", cx, cy);
  666. }
  667.  
  668. void CPokerView::OnDestroy()
  669. {
  670.     CView::OnDestroy();
  671.     
  672.     // TODO: Add your message handler code here
  673.     
  674. //     Shutdown the CARDS.DLL code.
  675.  
  676.     CDTTerm();
  677. }
  678.  
  679. void CPokerView::OnLButtonUp(UINT nFlags, CPoint point)
  680. {
  681. int        i;
  682.  
  683. //  Used only when selecting cards to discard...    
  684.     CPokerDoc* pDoc = GetDocument();
  685.  
  686.     for (i = 0; i < 5; i++)
  687.     {// Look at each of my cards...
  688.         if (point.x > pDoc->CardLocation[3][i].x && 
  689.             point.x < pDoc->CardLocation[3][i].x + pDoc->nWidth &&         
  690.             point.y > pDoc->CardLocation[3][i].y && 
  691.             point.y < pDoc->CardLocation[3][i].y + pDoc->nHeight)
  692.         {// This is the card selected!
  693.             if (pDoc->nCardState[3][i] == CARD_INVERT)
  694.             {// Toggle the card's display state:
  695.                 pDoc->nCardState[3][i] = CARD_OK;
  696.             }
  697.             else
  698.             {
  699.                 pDoc->nCardState[3][i] = CARD_INVERT;
  700.             }
  701.  
  702.             COLORREF Color = 0x00FFFFFF;
  703.             CClientDC dc(this);                         
  704.             CDTDraw(dc.GetSafeHdc(), 
  705.                 pDoc->CardLocation[3][i].x, 
  706.                 pDoc->CardLocation[3][i].y, 
  707.                 PlayerCard(3, i), 
  708.                 CardDrawMode(3, i), 
  709.                 Color);
  710.         }         
  711.     }    
  712.     
  713.     CView::OnLButtonUp(nFlags, point);
  714. }
  715.  
  716. void CPokerView::OnFileNewgame()
  717. {
  718.     // TODO: Add your command handler code here
  719.     CPokerDoc* pDoc = GetDocument();
  720.     pDoc->NewGame();
  721.     InvalidateRect(NULL, TRUE);
  722. }
  723.  
  724. void CPokerView::OnLButtonDown(UINT nFlags, CPoint point)
  725. {// We don't care for button down messages in this version.
  726.     // TODO: Add your message handler code here and/or call default
  727.     CView::OnLButtonDown(nFlags, point);
  728. }
  729.  
  730. void CPokerView::OnUpdateMovesBet(CCmdUI* pCmdUI)
  731. {
  732. // Enable the button if we can BET.
  733. int        i;
  734.  
  735.     CPokerDoc* pDoc = GetDocument();
  736.     
  737.     pDoc->bCanBet = TRUE;
  738.     
  739.     for (i = 0; i < NUMBER_PLAYERS; i++)
  740.     {    
  741.         if (pDoc->nPlayerAction[i] == BET || 
  742.             pDoc->nPlayerAction[i] == CALL ||
  743.             pDoc->nPlayerAction[i] == RAISE)
  744.         {
  745.             pDoc->bCanBet = FALSE;
  746.         }
  747.     }
  748.  
  749.     if (pDoc->bCanBet &&                   
  750.         pDoc->nPlayerAction[ME] != FOLD &&
  751.         pDoc->nCurrentPlayer == ME && 
  752.         pDoc->nGameState != WAIT)
  753.     {
  754.         pCmdUI->Enable(TRUE);
  755.     }
  756.     else
  757.     {
  758.         pCmdUI->Enable(FALSE);
  759.     }
  760. }
  761.  
  762. void CPokerView::OnUpdateMovesCall(CCmdUI* pCmdUI)
  763. {
  764. // Enable the button if we can CALL.
  765. int        i;
  766.  
  767.     CPokerDoc* pDoc = GetDocument();
  768.     
  769.     pDoc->bCanCall = FALSE;
  770.     
  771.     for (i = 0; i < NUMBER_PLAYERS; i++)
  772.     {    
  773.         if (pDoc->nPlayerAction[i] == BET || 
  774.             pDoc->nPlayerAction[i] == CALL ||
  775.             pDoc->nPlayerAction[i] == RAISE)
  776.         {
  777.             pDoc->bCanCall = TRUE;
  778.         }
  779.     }
  780.     
  781.     if (pDoc->bCanCall && 
  782.         pDoc->nPlayerAction[ME] != FOLD &&
  783.         pDoc->nCurrentPlayer == ME && 
  784.         pDoc->nGameState != DRAW_SELECT && 
  785.         pDoc->nGameState != DRAW_DISCARD && 
  786.         pDoc->nGameState != DRAW_DEAL && 
  787.         pDoc->nGameState != WAIT)
  788.     {
  789.         pCmdUI->Enable(TRUE);
  790.     }
  791.     else
  792.     {
  793.         pCmdUI->Enable(FALSE);
  794.     }
  795. }
  796.  
  797. void CPokerView::OnUpdateMovesCheck(CCmdUI* pCmdUI)
  798. {
  799. // Enable the button if we can CHECK.
  800. int        i;
  801.  
  802.     CPokerDoc* pDoc = GetDocument();
  803.     
  804.     pDoc->bCanCheck = TRUE;
  805.     for (i = 0; i < NUMBER_PLAYERS; i++)
  806.     {    
  807.         if (pDoc->nPlayerAction[i] != CHECK && pDoc->nPlayerAction[i] != NOTHING)
  808.         {
  809.             pDoc->bCanCheck = FALSE;
  810.         }
  811.     }
  812.     
  813.     if (pDoc->bCanCheck && 
  814.         pDoc->nPlayerAction[ME] != FOLD &&    
  815.         pDoc->nCurrentPlayer == ME && 
  816.         pDoc->nGameState != DRAW_SELECT && 
  817.         pDoc->nGameState != DRAW_DISCARD && 
  818.         pDoc->nGameState != DRAW_DEAL && 
  819.         pDoc->nGameState != WAIT)
  820.     {
  821.         pCmdUI->Enable(TRUE);
  822.     }
  823.     else
  824.     {
  825.         pCmdUI->Enable(FALSE);
  826.     }
  827. }
  828.  
  829. void CPokerView::OnUpdateMovesFold(CCmdUI* pCmdUI)
  830. {
  831. // Enable the button if we can FOLD.
  832.  
  833.     CPokerDoc* pDoc = GetDocument();
  834.     
  835.     if (pDoc->bCanFold && 
  836.         pDoc->nCurrentPlayer == ME && 
  837.         pDoc->nGameState != DRAW_SELECT && 
  838.         pDoc->nGameState != DRAW_DISCARD && 
  839.         pDoc->nGameState != DRAW_DEAL && 
  840.         pDoc->nGameState != WAIT)
  841.     {
  842.         pCmdUI->Enable(TRUE);
  843.     }
  844.     else
  845.     {
  846.         pCmdUI->Enable(FALSE);
  847.     }
  848. }
  849.  
  850. void CPokerView::OnUpdateMovesRaise(CCmdUI* pCmdUI)
  851. {
  852. // Enable the button if we can RAISE.
  853. int        i;
  854.  
  855.     CPokerDoc* pDoc = GetDocument();
  856.  
  857.     pDoc->bCanRaise = FALSE;
  858.     
  859.     for (i = 0; i < NUMBER_PLAYERS; i++)
  860.     {    
  861.         if (i != ME &&
  862.             (pDoc->nPlayerAction[i] == BET ||
  863.             pDoc->nPlayerAction[i] == RAISE))
  864.         {
  865.             pDoc->bCanRaise = TRUE;
  866.         }
  867.     }
  868.     
  869.     if (pDoc->bCanRaise && 
  870.         pDoc->nPlayerAction[ME] != FOLD &&    
  871.         pDoc->nCurrentPlayer == ME && 
  872.         pDoc->nGameState != DRAW_DISCARD && 
  873.         pDoc->nGameState != WAIT)
  874.     {
  875.         pCmdUI->Enable(TRUE);
  876.     }
  877.     else
  878.     {
  879.         pCmdUI->Enable(FALSE);
  880.     }
  881. }
  882.  
  883. void CPokerView::OnMovesBet()
  884. {// I've decided to bet.
  885. int    nCurrentBet = 0;
  886.  
  887.     CPokerDoc* pDoc = GetDocument();
  888.     CBetDlg Dialog;
  889.  
  890.     Dialog.DoModal();
  891.     
  892.     pDoc->Bet(ME, Dialog.m_nBetAmount);
  893.     pDoc->NextPlayer();
  894. }
  895.  
  896. void CPokerView::OnUpdateMovesDeal(CCmdUI* pCmdUI)
  897. {
  898. // The user can do a new deal with a button.
  899. int        bEnable = FALSE;
  900.  
  901.     CPokerDoc* pDoc = GetDocument();
  902.     
  903.     if (pDoc->nGameState > SHOWDOWN || 
  904.         (pDoc->nGameState == DRAW_SELECT && pDoc->nCurrentPlayer == ME))
  905.     {
  906.         bEnable = TRUE;
  907.     }
  908.     
  909.     pCmdUI->Enable(bEnable);
  910. }
  911.  
  912. void CPokerView::OnMovesDeal()
  913. {
  914.     // TODO: Add your command handler code here
  915.     TRACE("OnMovesDeal called\n");    
  916.     CPokerDoc* pDoc = GetDocument();
  917.     if (pDoc->nGameState >= SHOWDOWN)
  918.     {
  919.         pDoc->Deal();
  920.     }
  921.     else
  922.     {
  923.         TRACE("I've done my draw...\n");
  924.         pDoc->nPlayerAction[ME] = CHECK;    
  925.         pDoc->NextPlayer();
  926.     }
  927. }
  928.  
  929. void CPokerView::OnMovesCall()
  930. {
  931.     TRACE("OnMovesCall called\n");    
  932.     CPokerDoc* pDoc = GetDocument();
  933.     pDoc->Call(ME);
  934.     pDoc->NextPlayer();
  935. }
  936.  
  937. void CPokerView::OnMovesFold()
  938. {
  939.     TRACE("OnMovesFold called\n");    
  940.     CPokerDoc* pDoc = GetDocument();
  941.     pDoc->Fold(ME);
  942.     CClientDC dc(this);                         
  943.     DrawOnePlayer(&dc, ME);    
  944.     pDoc->NextPlayer();
  945. }
  946.  
  947. void CPokerView::OnMovesRaise()
  948. {
  949. int    nCurrentBet = 0;
  950.     TRACE("OnMovesBet called\n");    
  951.  
  952.     CPokerDoc* pDoc = GetDocument();
  953.     CBetDlg Dialog;
  954.  
  955.     Dialog.DoModal();
  956.     
  957.     pDoc->Raise(ME, Dialog.m_nBetAmount);
  958.     pDoc->NextPlayer();
  959. }
  960.