home *** CD-ROM | disk | FTP | other *** search
/ CD Direkt: Spezial 1 / CDD_SPIELE_.ISO / wingames / pyramid / pyramid.cpp < prev    next >
C/C++ Source or Header  |  1993-08-18  |  46KB  |  1,630 lines

  1. //-------------------------------------------------------------------
  2. //  PROGRAM:          PYRAMID.CPP
  3. //
  4. //  DESCRIPTION:      Sample program that utilizes Borland's
  5. //                    OWL
  6. //
  7. //                    Written by Carlos Yu
  8. //
  9. //  NOTE:             The program design is kinda hacked because
  10. //                    this is my first attempt at creating a
  11. //                    fully functional Windows program using
  12. //                    OWL and C++.
  13. //
  14. //                    Any suggestions on making the program better,
  15. //                    specially the DealCards module which is
  16. //                    painfully slow, would be greatly appreciated.
  17. //
  18. //                    Compuserve ID 72672,1567                    
  19. //-------------------------------------------------------------------
  20.  
  21.  
  22. //--------------------------------
  23. //  Include files
  24. //--------------------------------
  25.  
  26. #include <owl.h>                              
  27. #include <bwcc.h>                             
  28. #include <stdio.h>                              
  29. #include <string.h>
  30. #include <dialog.h>                             
  31. #include <button.h>                            
  32. #include <static.h>                           
  33. #include <bbutton.h>                            
  34. #include <bgrpbox.h>                           
  35. #include <tcollect.h>                        
  36.  
  37.  
  38.  
  39. //--------------------------------
  40. //  User Include Files
  41. //--------------------------------
  42.  
  43. #include "cardwin.h"
  44. #include "CDialog.h"
  45.  
  46. //-------------------------------------------------------------------
  47. //  GLOBAL VARIABLES AND DEFINITIONS
  48. //-------------------------------------------------------------------
  49. //--------------------------------
  50. //  Menu Item Constants
  51. //--------------------------------
  52.  
  53. #define       CM_DEAL          101
  54. #define       CM_OPTIONS       102
  55. #define       CM_QUIT          103
  56. #define       CM_INSTRUCT      104
  57. #define       CM_ABOUT         105
  58.  
  59.  
  60. //--------------------------------
  61. //  Push Button Constants
  62. //--------------------------------
  63.  
  64. #define       ID_DEAL          111
  65. #define       ID_OPTIONS       112
  66. #define       ID_QUIT          113
  67. #define       ID_INSTRUCT      114
  68. #define       ID_ABOUT         115
  69.  
  70. //--------------------------------
  71. //  Custom Control Constants
  72. //--------------------------------
  73.  
  74. #define       ID_STATUSGROUP   121
  75. #define       ID_STATUSTEXT    122
  76.  
  77.  
  78. //--------------------------------
  79. //  Constant variables
  80. //--------------------------------
  81.  
  82. #define       DIALOGQUIT       400
  83. #define       DIALOGPLAY       800
  84. #define       DIALOGABOUT      500
  85. #define       DIALOGINSTRUCT   600
  86.  
  87. #define       MAINMENU         100
  88. #define       MAINACCEL        100
  89. #define       MAINICON         100
  90.  
  91. #define       WINWIDTH         301
  92. #define       WINHEIGHT        240
  93.  
  94. #define       STATUSLEN        255
  95.  
  96. #define       WINBITMSG        589
  97. #define       BACKGROUNDBIT   7777
  98.  
  99. #define       ORIGIN_X          43
  100. #define       ORIGIN_Y          20
  101.  
  102. #define       CHILD_CLICK       20
  103.  
  104.  
  105. POINT PYRAMID_POS[] =
  106. {
  107.     { ORIGIN_X + 222, ORIGIN_Y },
  108.     { ORIGIN_X + 185, ORIGIN_Y +  25 },
  109.     { ORIGIN_X + 259, ORIGIN_Y +  25 },
  110.     { ORIGIN_X + 148, ORIGIN_Y +  50 },
  111.     { ORIGIN_X + 222, ORIGIN_Y +  50 },
  112.     { ORIGIN_X + 296, ORIGIN_Y +  50 },
  113.     { ORIGIN_X + 111, ORIGIN_Y +  75 },
  114.     { ORIGIN_X + 185, ORIGIN_Y +  75 },
  115.     { ORIGIN_X + 259, ORIGIN_Y +  75 },
  116.     { ORIGIN_X + 333, ORIGIN_Y +  75 },
  117.     { ORIGIN_X +  74, ORIGIN_Y + 100 },
  118.     { ORIGIN_X + 148, ORIGIN_Y + 100 },
  119.     { ORIGIN_X + 222, ORIGIN_Y + 100 },
  120.     { ORIGIN_X + 296, ORIGIN_Y + 100 },
  121.     { ORIGIN_X + 370, ORIGIN_Y + 100 },
  122.     { ORIGIN_X +  37, ORIGIN_Y + 125 },
  123.     { ORIGIN_X + 111, ORIGIN_Y + 125 },
  124.     { ORIGIN_X + 185, ORIGIN_Y + 125 },
  125.     { ORIGIN_X + 259, ORIGIN_Y + 125 },
  126.     { ORIGIN_X + 333, ORIGIN_Y + 125 },
  127.     { ORIGIN_X + 407, ORIGIN_Y + 125 },
  128.     { ORIGIN_X,       ORIGIN_Y + 150 },
  129.     { ORIGIN_X +  74, ORIGIN_Y + 150 },
  130.     { ORIGIN_X + 148, ORIGIN_Y + 150 },
  131.     { ORIGIN_X + 222, ORIGIN_Y + 150 },
  132.     { ORIGIN_X + 296, ORIGIN_Y + 150 },
  133.     { ORIGIN_X + 370, ORIGIN_Y + 150 },
  134.     { ORIGIN_X + 444, ORIGIN_Y + 150 }
  135. };
  136.  
  137.  
  138. /*******************************************************************
  139.  *******************************************************************
  140.  ************************  PROGRAM STARTS  *************************
  141.  *******************************************************************
  142.  *******************************************************************/
  143. //-------------------------------------------------------------------
  144. //  CLASS:            TPyramidApp
  145. //
  146. //  DESCRIPTION:      Derive TApplication to create TPyramidApp 
  147. //
  148. //  RETURNS:          NONE
  149. //-------------------------------------------------------------------         
  150.  
  151. class TPyramidApp : public TApplication
  152. {
  153. public:
  154.     TPyramidApp(LPSTR AName, HINSTANCE hInstance, HINSTANCE hPrevInstance,
  155.         LPSTR lpCmdLine, int nCmdShow) : TApplication(AName, hInstance,
  156.         hPrevInstance, lpCmdLine, nCmdShow) {};
  157.  
  158.     virtual void InitInstance();
  159.     virtual void InitMainWindow();
  160. };
  161.  
  162.  
  163. //-------------------------------------------------------------------
  164. //  CLASS:            TPyramidWin
  165. //
  166. //  DESCRIPTION:      Derive TWindow to create TPyramidWin which is
  167. //                    the main window class of the application
  168. //
  169. //  RETURNS:          NONE
  170. //-------------------------------------------------------------------
  171.  
  172. _CLASSDEF(TPyramidWin)
  173. class TPyramidWin : public TWindow
  174. {
  175. private:
  176.     int               tagIdx,
  177.                       playIdx,
  178.                       childIndex,
  179.                       discardCount;
  180.  
  181.     char              statusMsg[255];
  182.  
  183.     BOOL              isTagged,
  184.                       hasDealt,
  185.                       playOccupied;
  186.  
  187.     HMENU             MenuHandle,
  188.                       MenuPopup1,
  189.                       MenuPopup2,
  190.                       MenuSystem;
  191.  
  192.     HBRUSH            GrayBrush;
  193.     HBITMAP           hBitBack;
  194.  
  195.     PTStatic          StatusText;
  196.     PTButton          PushDeal,
  197.                       PushAbout,
  198.                       PushInstruct,
  199.                       PushQuit;
  200.     PTBGroupBox       StatusGroup;
  201.     PTNSCollection    allObjects;
  202.     PTCardWin         cardPtr[53];
  203.  
  204. public:
  205.  
  206.     // Constructor
  207.  
  208.     TPyramidWin(PTWindowsObject AParent, LPSTR ATitle);
  209.  
  210.     //----------------------------
  211.     //  Window default functions
  212.     //         and events
  213.     //----------------------------
  214.  
  215.     virtual BOOL  CanClose();
  216.     virtual void  SetupWindow();
  217.     virtual LPSTR GetClassName();
  218.     virtual void  GetWindowClass(WNDCLASS& AWndClass);
  219.  
  220.     virtual void  WMMove(RTMessage Msg)
  221.         = [WM_FIRST + WM_MOVE];
  222.  
  223.     virtual void  WMEraseBkgnd(RTMessage)
  224.         = [WM_FIRST + WM_ERASEBKGND];
  225.  
  226.     virtual void  WMDestroy(RTMessage Msg)
  227.         = [WM_FIRST + WM_DESTROY];
  228.  
  229.     virtual void  WMCtlColor(RTMessage Msg)
  230.         = [WM_FIRST + WM_CTLCOLOR];
  231.  
  232.     virtual void  WMMouseMove(RTMessage)
  233.         = [WM_FIRST + WM_MOUSEMOVE];
  234.  
  235.     virtual void  WMMenuSelect(RTMessage Msg)
  236.         = [WM_FIRST + WM_MENUSELECT];
  237.  
  238.     virtual void  WMLButtonDown(RTMessage Msg)
  239.         = [WM_FIRST + WM_LBUTTONDOWN];
  240.  
  241.     virtual void  WMRButtonDown(RTMessage Msg)
  242.         = [WM_FIRST + WM_RBUTTONDOWN];
  243.  
  244.     //----------------------------
  245.     //  User functions
  246.     //----------------------------
  247.  
  248.     virtual void  WMNotifyClick(RTMessage Msg)
  249.         = [WM_USER + CHILD_CLICK];
  250.  
  251.     void Animate();
  252.  
  253.     BOOL TestKing();
  254.  
  255.     void DealCards();
  256.  
  257.     void PlayAgain();
  258.  
  259.     BOOL ProcessTag();
  260.  
  261.     void ReturnToDeck();
  262.  
  263.     void InitializeDeck();
  264.  
  265.     int  GetValue(int Value);
  266.  
  267.  
  268.     //---------------
  269.     //  Push Button
  270.     //---------------
  271.  
  272.     virtual void  IDQuit(RTMessage)
  273.         = [ID_FIRST + ID_QUIT];
  274.  
  275.     virtual void  IDDeal(RTMessage)
  276.         = [ID_FIRST + ID_DEAL];
  277.  
  278.     virtual void  IDInstruct(RTMessage)
  279.         = [ID_FIRST +