home *** CD-ROM | disk | FTP | other *** search
/ vsiftp.vmssoftware.com / VSIPUBLIC@vsiftp.vmssoftware.com.tar / FREEWARE / FREEWARE40.ZIP / caribbeanstud / table.cpp < prev    next >
Text File  |  1997-12-07  |  33KB  |  940 lines

  1. /*
  2.  * (c) Copyright 1997, Qun Zhang.
  3.  *
  4.  * Permission to use, copy, modify, distribute, and sell this software
  5.  * and its documentation for any purpose is hereby granted without fee,
  6.  * provided that the above copyright notice appear in all copies and
  7.  * that both that copyright notice and this permission notice appear in
  8.  * supporting documentation, and that the name of Qun Zhang not be used
  9.  * in advertising or publicity pertaining to distribution of the software
  10.  * without specific, written prior permission.  Qun Zhang make no
  11.  * representations about the suitability of this software for any purpose.
  12.  * It is provided "as is" without express or implied warranty.
  13.  *
  14.  * THE ABOVE-NAMED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  15.  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  16.  * EVENT SHALL THE ABOVE-NAMED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  17.  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  18.  * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  19.  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  20.  * PERFORMANCE OF THIS SOFTWARE.
  21.  *
  22.  */
  23.  
  24. #include <iostream.h>
  25. #include <X11/Xatom.h>
  26. #include <X11/Intrinsic.h>
  27. #include <X11/Xutil.h>
  28. #include <X11/Shell.h>
  29.  
  30. #include <Xm/Xm.h>
  31. //#include <Xm/DialogS.h>
  32. #include <Xm/MessageB.h>
  33. #include <Xm/DrawingA.h>
  34. #include <Xm/Form.h>
  35. #include <Xm/Label.h>
  36. #include <Xm/Scale.h>
  37. #include <Xm/ScrollBar.h>
  38. #include <Xm/ToggleB.h>
  39. #include <Xm/PushBG.h>
  40. #include <Xm/SeparatoG.h>
  41. #include <Xm/Text.h>
  42.  
  43. #include <stdio.h>
  44. #include <stdlib.h>
  45. #include <assert.h>
  46. #include "Dealer.h"
  47. #include "Player.h"
  48. #include "Table.h"
  49.  
  50. #define XtNbetUnit "betUnit"
  51. #define XtCbetUnit "betUnit"
  52. #define XtNminBet "minBet"
  53. #define XtCminBet "minBet"
  54. #define XtNbankroll "bankroll"
  55. #define XtCbankroll "bankroll"
  56. #define XtNjackpot "jackpot"
  57. #define XtCjackpot "jackpot"
  58. #define XtNminjackpot "minjackpot"
  59. #define XtCminjackpot "minjackpot"
  60. #define XtNplayers "players"
  61. #define XtCplayers "players"
  62.  
  63. typedef struct {
  64.   int bankroll;
  65.   int betUnit;
  66.   int minBet;
  67.   int jackpot;
  68.   int minjackpot;
  69.   int players;
  70.   } RValues, *RVptr;
  71.  
  72. RValues rv;
  73.  
  74. XtResource resources[] = {
  75.    { XtNbankroll, XtCbankroll, XtRInt, sizeof(int),
  76.      XtOffset(RVptr, bankroll), XtRImmediate, (XtPointer)100 },
  77.    { XtNbetUnit, XtCbetUnit, XtRInt, sizeof(int),
  78.      XtOffset(RVptr, betUnit), XtRImmediate, (XtPointer)1 },
  79.    { XtNminBet, XtCminBet, XtRInt, sizeof(int),
  80.      XtOffset(RVptr, minBet), XtRImmediate, (XtPointer)0 },
  81.    { XtNjackpot, XtCjackpot, XtRInt, sizeof(int),
  82.      XtOffset(RVptr, jackpot), XtRImmediate, (XtPointer)10000000 },
  83.    { XtNminjackpot, XtCminjackpot, XtRInt, sizeof(int),
  84.      XtOffset(RVptr, minjackpot), XtRImmediate, (XtPointer)1000000 },
  85.    { XtNplayers, XtCplayers, XtRInt, sizeof(int),
  86.      XtOffset(RVptr, players), XtRImmediate, (XtPointer)1 }
  87. };
  88.  
  89. Widget Table::toplevel = (Widget) NULL;
  90. Widget Table::Layout = (Widget) NULL;
  91. Widget Table::PlayTable = (Widget) NULL;
  92. Widget Table::ControlTable = (Widget) NULL;
  93. Widget Table::DealerHand = (Widget) NULL;
  94. Widget Table::DealButton = (Widget) NULL;
  95. Widget Table::PlayerHand = (Widget) NULL;
  96. Widget Table::AnteScroll = (Widget) NULL;
  97. Widget Table::BetButton = (Widget) NULL;
  98. Widget Table::FoldButton = (Widget) NULL;
  99. Widget Table::ProgressiveButton = (Widget) NULL;
  100. Widget Table::JackPotLabel = (Widget) NULL;
  101. Widget Table::ExceptionDialog = (Widget) NULL;
  102. Widget Table::YouHaveLabel[6] ;
  103. Widget Table::YouHaveLabelValue[6];
  104. Widget Table::YouWinLoseValue[6];
  105. Widget Table::DealerTableLabel;
  106.  
  107. Widget Table::HelpRulesDialog;
  108. Widget Table::HelpRulesButton;
  109. Widget Table::HelpRulesScrolledText;
  110.  
  111. void Table::SetLabel(Widget w, char* label)
  112. {
  113. #ifdef DEBUG
  114.        cout << "Calling Table::SetLabel: " << label <<endl;
  115. #endif
  116.    int i;
  117.    Arg args[5];
  118.    XmString s;
  119.  
  120.    assert(w != NULL);
  121.    s = XmStringCreate(label, XmSTRING_DEFAULT_CHARSET);
  122.  
  123.    i = 0;
  124.    XtSetArg(args[i], XmNlabelString, s);  i++;
  125.    XtSetValues(w, args, i);
  126.    XmStringFree(s);
  127. }
  128.  
  129. void Table::Initialize()
  130. {
  131.  
  132. #ifdef DEBUG
  133.        cout << "BankRoll: " <<  _bankroll <<endl;
  134.     cout << "BetUnit: " << _betUnit <<endl;
  135.     cout << "Minimum Bet: " << _minBet <<endl;
  136.     cout << "JackPot: " <<  _jackpot <<endl;
  137.     cout << "JackPot: " <<  _minjackpot <<endl;
  138.     cout << "Number Of Players: " <<  _totalSeats <<endl;
  139. #endif
  140.      _dealerFace = 0;
  141.      _playerSeats[0] = new DealerSeat(this);
  142.      _dealer = new Dealer(_playerSeats[0]);
  143.     _dealer->JackPot(_jackpot);
  144.     _dealer->MinJackPot(_minjackpot);
  145.  
  146.     Player * player; 
  147.     for(int i =1; i <= _players; i++)
  148.      {
  149.         _playerSeats[i] = new PlayerSeat(this, (i-1)*100/_players,
  150.                                                             i*100/_players);
  151.          player = new Player(_dealer, _playerSeats[i]);
  152.          _dealer->Add(player);
  153.          player->BankRoll(_bankroll);
  154.      }
  155.     CurrentSeat(0);
  156.     Disable( BetButton ) ;
  157.     Disable( FoldButton) ;
  158. }
  159.  
  160. Table::Table(int argc, char **argv) :  _dealer(0)
  161. {
  162.  
  163. #ifndef VMS
  164.    try{
  165. #endif
  166.    XtSetLanguageProc ( (XtAppContext) NULL, (XtLanguageProc) NULL, (XtPointer) NULL );
  167.    XtToolkitInitialize ();
  168.    app_context = XtCreateApplicationContext ();
  169.    _display = XtOpenDisplay (app_context, NULL, argv[0], "CaribbeanStud",
  170.                             NULL, 0, &argc, argv);
  171.    int scr = DefaultScreen(_display);
  172.    if (!_display)
  173.    {
  174.        printf("%s: can't open display, exiting...\n", argv[0]);
  175.        exit (-1);
  176.    }
  177.  
  178.     CreateWidgets ( _display, argv[0], argc, argv);
  179.     AddCallbacks();
  180.     XtRealizeWidget (toplevel);
  181.     Initialize();
  182. #ifndef VMS
  183.    }
  184.    catch(const char *msg)
  185.    {
  186.       Table::DoExceptionDialog(msg);
  187. #ifdef DEBUG
  188.       cout << msg << endl;
  189. #endif
  190.    }
  191. #endif  /* VMS */
  192. }
  193.  
  194. Table::~Table()
  195. {
  196.     for(int i=0; i<_totalSeats; i++)
  197.         delete _playerSeats[i];
  198.     delete _dealer;
  199. }
  200.  
  201. void Table::CreateWidgets(Display *display, char *app_name, int app_argc,
  202.                                   char **app_argv)
  203. {
  204.     Widget children[6];      /* Children to manage */
  205.     Arg al[64];                    /* Arg List */
  206.     register int ac = 0;           /* Arg Count */
  207.     char  str[50];    /* temporary storage for XmStrings */
  208.  
  209.     XtSetArg(al[ac], XmNallowShellResize, TRUE); ac++;
  210. //   XtSetArg(al[ac], XmNargc, app_argc); ac++;
  211. //   XtSetArg(al[ac], XmNargv, app_argv); ac++;
  212.  
  213.  
  214.     toplevel = XtAppCreateShell ( app_name, "CaribbeanStud", applicationShellWidgetClass, display, al, ac );
  215.  
  216.    XtGetApplicationResources(toplevel, (unsigned char *)&rv, resources,
  217.              XtNumber(resources), NULL, 0);
  218.   
  219.     _bankroll = rv.bankroll;
  220.     _betUnit =  rv.betUnit;
  221.     _minBet =   rv.minBet;
  222.     _jackpot =  rv.jackpot;
  223.     _minjackpot =  rv.minjackpot;
  224.     _players =  (rv.players > 6 ) ? 6 : rv.players;
  225.     _totalSeats = _players;
  226.  
  227.     ac = 0;
  228.     XtSetArg(al[ac], XmNdialogStyle, XmDIALOG_APPLICATION_MODAL); ac++;
  229.    ExceptionDialog = XmCreateMessageDialog(toplevel,
  230.          "ExceptionDialog", al, ac);
  231.  
  232.     ac = 0;
  233.     XtSetArg(al[ac], XmNmarginWidth, 0); ac++;
  234.     XtSetArg(al[ac], XmNmarginHeight, 0); ac++;
  235.     XtSetArg(al[ac], XmNadjustLast, TRUE); ac++;
  236.     XtSetArg(al[ac], XmNadjustMargin, TRUE); ac++;
  237.     XtSetArg(al[ac], XmNrubberPositioning, TRUE); ac++;
  238.     Layout = XmCreateForm ( toplevel, "Layout", al, ac );
  239.  
  240.    // control table
  241.     ac = 0;
  242.     XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
  243.     XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_FORM); ac++;
  244.     XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
  245.     XtSetArg(al[ac], XmNrightAttachment, XmATTACH_POSITION); ac++;
  246.     XtSetArg(al[ac], XmNrightPosition, 35); ac++;
  247.     XtSetArg(al[ac], XmNrubberPositioning, TRUE); ac++;
  248.     ControlTable = XmCreateForm ( Layout, "ControlTable", al, ac );
  249.  
  250.    // play Table 
  251.     ac = 0;
  252.     XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
  253.     XtSetArg(al[ac], XmNtopOffset, 20); ac++;
  254.     XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_FORM); ac++;
  255.     XtSetArg(al[ac], XmNbottomOffset, 20); ac++;
  256.     XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
  257.     XtSetArg(al[ac], XmNrightOffset, 20); ac++;
  258.     XtSetArg(al[ac], XmNleftAttachment, XmATTACH_WIDGET); ac++;
  259.     XtSetArg(al[ac], XmNleftWidget, ControlTable); ac++;
  260.     XtSetArg(al[ac], XmNrubberPositioning, TRUE); ac++;
  261.     PlayTable = XmCreateForm ( Layout, "PlayTable", al, ac );
  262.    // For all the contral Items
  263.  
  264.    // JackPot 
  265.  
  266.    ac = 0;  
  267.     XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
  268.     XtSetArg(al[ac], XmNtopOffset, 20); ac++;
  269.    XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
  270.    XtSetArg(al[ac], XmNrightOffset, 20); ac++;
  271.    XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
  272.     XtSetArg(al[ac], XmNleftOffset, 10); ac++;
  273.    XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_NONE); ac++;
  274.    XColor      color;
  275.    Colormap cmap = DefaultColormap(_display, DefaultScreen(_display));
  276.    color.red = 52428;
  277.    color.green = color.blue = 0;
  278.    XAllocColor(display, cmap, &color);
  279.    XtSetArg(al[ac], XmNforeground, color.pixel);   ac++;
  280.    JackPotLabel = XmCreateLabel(ControlTable, "JackPotLabel", al, ac);
  281.     sprintf(str, "JACKPOT: %d", rv.jackpot);
  282.    SetLabel(JackPotLabel, str);
  283.    XtManageChild(JackPotLabel);
  284.  
  285.    ac = 0;
  286.    XtSetArg(al[ac], XmNtopAttachment, XmATTACH_WIDGET); ac++;
  287.    XtSetArg(al[ac], XmNtopWidget, JackPotLabel); ac++;
  288.    XtSetArg(al[ac], XmNtopOffset, 10); ac++;
  289.    XtSetArg(al[ac], XmNrightAttachment, XmATTACH_POSITION); ac++;
  290.    XtSetArg(al[ac], XmNleftAttachment, XmATTACH_POSITION); ac++;
  291.    XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_POSITION); ac++;
  292.    XtSetArg(al[ac], XmNbottomPosition, 20); ac++;
  293.    XtSetArg(al[ac], XmNalignment, XmALIGNMENT_CENTER); ac++;
  294.    char name[50];
  295.    XmString s;
  296.    for(int j=0; j < rv.players; j++)
  297.    {
  298.       XtSetArg(al[ac], XmNleftPosition, j*100/rv.players);
  299.       XtSetArg(al[ac+1], XmNrightPosition,(j+1)*100/rv.players);
  300.       sprintf(name, "YouHaveLabel%i" , j+1);
  301.       YouHaveLabel[j] = XmCreateLabel(ControlTable, name, al, ac +2);
  302.       sprintf(name, " Player %i:  " , j+1);
  303.       SetLabel(YouHaveLabel[j], name);
  304.    }
  305.  
  306.    ac = 0;
  307.     XtSetArg(al[ac], XmNtopAttachment, XmATTACH_WIDGET); ac++;
  308.    XtSetArg(al[ac], XmNrightAttachment, XmATTACH_POSITION); ac++;
  309.    XtSetArg(al[ac], XmNleftAttachment, XmATTACH_POSITION); ac++;
  310.     XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_POSITION); ac++;
  311.     XtSetArg(al[ac], XmNbottomPosition, 30); ac++;
  312.    XtSetArg(al[ac], XmNalignment, XmALIGNMENT_CENTER); ac++;
  313.    for(j=0; j < rv.players; j++) 
  314.    { 
  315.         XtSetArg(al[ac], XmNtopWidget, YouHaveLabel[j]);
  316.       XtSetArg(al[ac+1], XmNleftPosition, j*100/rv.players); 
  317.       XtSetArg(al[ac+2], XmNrightPosition,(j+1)*100/rv.players); 
  318.       sprintf(name, "YouHaveLabelValue%i" , j+1);
  319.       YouHaveLabelValue[j] = XmCreateLabel(ControlTable, name, al, ac +3); 
  320.       sprintf(str, "$%d", rv.bankroll);
  321.       SetLabel(YouHaveLabelValue[j], str);
  322.    }
  323.  
  324.    ac = 0;
  325.    XtSetArg(al[ac], XmNtopAttachment, XmATTACH_WIDGET); ac++;
  326.    XtSetArg(al[ac], XmNrightAttachment, XmATTACH_POSITION); ac++;
  327.    XtSetArg(al[ac], XmNleftAttachment, XmATTACH_POSITION); ac++;
  328.    XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_POSITION); ac++;
  329.    XtSetArg(al[ac], XmNbottomPosition, 40); ac++;
  330.    XtSetArg(al[ac], XmNalignment, XmALIGNMENT_CENTER); ac++;
  331.    for(j=0; j < rv.players; j++)
  332.    {
  333.       XtSetArg(al[ac], XmNtopWidget, YouHaveLabelValue[j]);
  334.       XtSetArg(al[ac+1], XmNleftPosition, j*100/rv.players);
  335.       XtSetArg(al[ac+2], XmNrightPosition,(j+1)*100/rv.players);
  336.       sprintf(name, "YouWinLoseValue%i" , j+1);
  337.       YouWinLoseValue[j] = XmCreateLabel(ControlTable, name, al, ac +3);
  338.       SetLabel(YouWinLoseValue[j], "");
  339.    }
  340.  
  341.    // dealbutton
  342.    ac = 0;
  343.     XtSetArg(al[ac], XmNtopAttachment, XmATTACH_POSITION); ac++;
  344.     XtSetArg(al[ac], XmNtopPosition, 40); ac++;
  345.     XtSetArg(al[ac], XmNleftAttachment, XmATTACH_POSITION); ac++;
  346.     XtSetArg(al[ac], XmNleftPosition, 40); ac++;
  347.    XtSetArg(al[ac], XmNrightAttachment, XmATTACH_POSITION); ac++;
  348.     XtSetArg(al[ac], XmNrightPosition, 65); ac++;
  349.    XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_POSITION); ac++;
  350.    XtSetArg(al[ac], XmNbottomPosition, 50); ac++;
  351.     DealButton = XmCreatePushButtonGadget ( ControlTable, "DealButton", al, ac );
  352.  
  353.  
  354.    // player.progressiveButton
  355.     ac = 0;
  356.     XtSetArg(al[ac], XmNtopAttachment, XmATTACH_POSITION); ac++;
  357.     XtSetArg(al[ac], XmNtopPosition, 52); ac++;
  358.     XtSetArg(al[ac], XmNleftAttachment, XmATTACH_POSITION); ac++;
  359.     XtSetArg(al[ac], XmNleftPosition, 15); ac++;
  360.     XtSetArg(al[ac], XmNrightAttachment, XmATTACH_POSITION); ac++;
  361.     XtSetArg(al[ac], XmNrightPosition, 85); ac++;
  362.     XtSetArg(al[ac], XmNmarginTop, 5); ac++;
  363.     XtSetArg(al[ac], XmNmarginBottom, 5); ac++;
  364.    XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_POSITION); ac++;
  365.    XtSetArg(al[ac], XmNbottomPosition, 62); ac++;
  366.     ProgressiveButton = XmCreateToggleButton ( ControlTable, "ProgressiveButton", al, ac );
  367.  
  368.    // playerform.antescroll
  369.     ac = 0;
  370.     XtSetArg(al[ac], XmNtopAttachment, XmATTACH_POSITION); ac++;
  371.     XtSetArg(al[ac], XmNtopPosition, 64); ac++;
  372.    XtSetArg(al[ac], XmNleftAttachment, XmATTACH_POSITION); ac++;
  373.     XtSetArg(al[ac], XmNleftPosition, 15); ac++;
  374.    XtSetArg(al[ac], XmNrightAttachment, XmATTACH_POSITION); ac++;
  375.    XtSetArg(al[ac], XmNrightPosition, 85); ac++;
  376.    XtSetArg(al[ac], XmNmaximum, rv.bankroll/3); ac++;
  377.    if(rv.bankroll/3 >= rv.minBet)
  378.        XtSetArg(al[ac], XmNminimum, rv.minBet);
  379.     else
  380.        XtSetArg(al[ac], XmNminimum, 0);
  381.    ac++;
  382.    XtSetArg(al[ac], XmNorientation, XmHORIZONTAL); ac++;
  383.    XtSetArg(al[ac], XmNshowValue, True); ac++;
  384.    XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_POSITION); ac++;
  385.    XtSetArg(al[ac], XmNbottomPosition, 77); ac++;
  386.     AnteScroll = XmCreateScale ( ControlTable, "AnteScroll", al, ac );
  387.  
  388.  
  389.    // player.betbutton
  390.     ac = 0;
  391.     XtSetArg(al[ac], XmNtopAttachment, XmATTACH_POSITION); ac++;
  392.     XtSetArg(al[ac], XmNtopPosition, 80); ac++;
  393.    XtSetArg(al[ac], XmNleftAttachment, XmATTACH_POSITION); ac++;
  394.     XtSetArg(al[ac], XmNleftPosition, 15); ac++;
  395.    XtSetArg(al[ac], XmNrightAttachment, XmATTACH_POSITION); ac++;
  396.    XtSetArg(al[ac], XmNrightPosition, 45); ac++;
  397.    XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_POSITION); ac++;
  398.    XtSetArg(al[ac], XmNbottomPosition, 90); ac++;
  399.     BetButton = XmCreatePushButtonGadget( ControlTable, "BetButton", al, ac );
  400.  
  401.    // player.foldbutton
  402.    ac = 0;  
  403.     XtSetArg(al[ac], XmNtopAttachment, XmATTACH_POSITION); ac++;
  404.     XtSetArg(al[ac], XmNtopPosition, 80); ac++;
  405.    XtSetArg(al[ac], XmNleftAttachment, XmATTACH_POSITION); ac++;
  406.     XtSetArg(al[ac], XmNleftPosition, 55); ac++;
  407.    XtSetArg(al[ac], XmNrightAttachment, XmATTACH_POSITION); ac++;
  408.    XtSetArg(al[ac], XmNrightPosition, 85); ac++;
  409.    XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_POSITION); ac++;
  410.    XtSetArg(al[ac], XmNbottomPosition, 90); ac++;
  411.    FoldButton = XmCreatePushButtonGadget ( ControlTable, "FoldButton", al, ac );
  412.  
  413.    // For PlayTable
  414.  
  415.    ac = 0;
  416.    XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
  417.    XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
  418.    XtSetArg(al[ac], XmNleftAttachment, XmATTACH_POSITION); ac++;
  419.    XtSetArg(al[ac], XmNleftPosition, 85); ac++;
  420.    XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_POSITION); ac++;
  421.    XtSetArg(al[ac], XmNbottomPosition, 8);   ac++;
  422.    HelpRulesButton = XmCreatePushButtonGadget(PlayTable, "HelpRulesButton", al, ac);
  423.    XtManageChild(HelpRulesButton);
  424.  
  425.    ac = 0;
  426.    XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
  427.    XtSetArg(al[ac], XmNrightAttachment, XmATTACH_WIDGET); ac++;
  428.    XtSetArg(al[ac], XmNrightWidget, HelpRulesButton); ac++;
  429.    XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
  430.    XtSetArg(al[ac], XmNforeground, color.pixel);   ac++;
  431.    XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_POSITION); ac++;
  432.    XtSetArg(al[ac], XmNbottomPosition, 8);   ac++;
  433.    DealerTableLabel = XmCreateLabel(PlayTable, "DealerLabel", al, ac);
  434.    SetLabel(DealerTableLabel, "");
  435.    XtManageChild(DealerTableLabel);
  436.  
  437.    // dealer draw area
  438.    ac = 0;
  439.     XtSetArg(al[ac], XmNtopAttachment, XmATTACH_WIDGET); ac++;
  440.     XtSetArg(al[ac], XmNtopWidget, DealerTableLabel); ac++;
  441.     XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_POSITION); ac++;
  442.     XtSetArg(al[ac], XmNbottomPosition, 55); ac++;
  443.    XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
  444.    XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
  445.     DealerHand = XmCreateDrawingArea ( PlayTable, "DealerHand", al, ac );
  446.  
  447.    // player draw area
  448.    ac = 0;
  449.     XtSetArg(al[ac], XmNtopAttachment, XmATTACH_WIDGET); ac++;
  450.     XtSetArg(al[ac], XmNtopWidget, DealerHand); ac++;
  451.    XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_FORM); ac++;
  452.    XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
  453.    XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
  454.     PlayerHand = XmCreateDrawingArea ( PlayTable, "PlayerHand", al, ac );
  455.  
  456.    // For help on Rules.
  457.  
  458.    HelpRulesDialog =  XmCreateFormDialog(toplevel,
  459.             "HelpRulesDialog", NULL, 0);
  460.  
  461.  
  462.    ac = 0;
  463.     XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
  464.    XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_FORM); ac++;
  465.    XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
  466.    XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
  467.    HelpRulesScrolledText = XmCreateScrolledText(HelpRulesDialog,
  468.             "HelpRulesScrolledText", al , ac);
  469.    XtManageChild(HelpRulesScrolledText);
  470.  
  471.  
  472.    for(j=0; j< rv.players; j++)
  473.     {
  474.       ac = 0;
  475.       children[ac++] = YouHaveLabel[j];
  476.       children[ac++] = YouHaveLabelValue[j];
  477.       children[ac++] = YouWinLoseValue[j];
  478.       XtManageChildren(children, ac);
  479.     }
  480.  
  481.     ac = 0;
  482.     children[ac++] = DealButton;
  483.     XtManageChildren(children, ac);
  484.  
  485.     ac = 0;
  486.     children[ac++] = AnteScroll;
  487.     XtManageChildren(children, ac);
  488.     ac = 0;
  489.     children[ac++] = BetButton;
  490.     children[ac++] = FoldButton;
  491.     XtManageChildren(children, ac);
  492.     ac = 0;
  493.     children[ac++] = ProgressiveButton;
  494.     XtManageChildren(children, ac);
  495.     ac = 0;
  496.     children[ac++] = PlayerHand;
  497.     XtManageChildren(children, ac);
  498.     ac = 0;
  499.     children[ac++] = DealerHand;
  500.     XtManageChildren(children, ac);
  501.    ac = 0;
  502.    children[ac++] = PlayTable;
  503.    children[ac++] = ControlTable;
  504.    XtManageChildren(children, ac);
  505.     ac = 0;
  506.     XtManageChild ( Layout );
  507. }
  508.  
  509. void Table::AddCallbacks()
  510. {
  511.    XtAddCallback( DealerHand ,XmNexposeCallback, 
  512.                      (void(*)(_WidgetRec*, void*, void*))Table::DealerDrawingAreaCB,this);
  513.    XtAddCallback( DealerHand, XmNresizeCallback, 
  514.                      (void(*)(_WidgetRec*, void*, void*))Table::DealerDrawingAreaCB, this);
  515.    XtAddCallback( PlayerHand ,XmNresizeCallback, 
  516.                      (void(*)(_WidgetRec*, void*, void*))Table::PlayerDrawingAreaCB, this);
  517.    XtAddCallback( PlayerHand ,XmNexposeCallback, 
  518.                      (void(*)(_WidgetRec*, void*, void*))Table::PlayerDrawingAreaCB, this);
  519.    XtAddCallback( DealButton, XmNactivateCallback, 
  520.                      (void(*)(_WidgetRec*, void*, void*))Table::DealCB, this);
  521.    XtAddCallback( BetButton,  XmNactivateCallback, 
  522.                      (void(*)(_WidgetRec*, void*, void*))Table::BetCB,  this);
  523.    XtAddCallback( FoldButton, XmNactivateCallback, 
  524.                      (void(*)(_WidgetRec*, void*, void*))Table::FoldCB, this);
  525.    XtAddCallback( AnteScroll,XmNvalueChangedCallback, 
  526.                      (void(*)(_WidgetRec*, void*, void*))Table::AnteScrollCB,this);
  527.    XtAddCallback(HelpRulesButton, XmNactivateCallback,
  528.                  (void(*)(_WidgetRec*, void*, void*))ManageHelpRulesDialogCB, this);
  529. //   XtAddCallback(ExceptionDialog, XmNfocusCallback,
  530. //                 (void(*)(_WidgetRec*, void*, void*))DoNothing, NULL);
  531.  
  532. }
  533.  
  534. void Table::DoExceptionDialog(const char *str)
  535. {
  536.    int i = 0;
  537.    XmString s;
  538.    Arg args[5];
  539.  
  540.    i = 0;
  541.    s = XmStringCreate(str, XmSTRING_DEFAULT_CHARSET);
  542.    XtSetArg(args[i], XmNmessageString, s);   i++;
  543.    XtSetValues(ExceptionDialog, args, i);
  544.    XmStringFree(s);
  545.    XtUnmanageChild(XmMessageBoxGetChild(ExceptionDialog,
  546.                XmDIALOG_CANCEL_BUTTON));
  547.    XtUnmanageChild(XmMessageBoxGetChild(ExceptionDialog,
  548.                XmDIALOG_HELP_BUTTON));
  549.    XtManageChild(ExceptionDialog);
  550.    XtPopup(XtParent(ExceptionDialog), XtGrabNone);
  551. }
  552.  
  553. void Table::CurrentSeat(int whichone)
  554. {
  555.  
  556.    if(_players <= 1) return;
  557.  
  558.    Arg args[5];
  559.    int i = 0;
  560.    Pixel forg, back;
  561.    char  label[50];
  562.  
  563.    
  564.    XtSetArg(args[i], XmNforeground, &forg); i++;
  565.    XtSetArg(args[i], XmNbackground, &back); i++;
  566.    XtGetValues( YouHaveLabelValue[0], args, i);
  567.  
  568.    for(int j=0; j < _players; j++)
  569.    {
  570.       sprintf(label, "Player %d: ", j+1);
  571.       i=0;
  572.       if(j == whichone){
  573.         XtSetArg(args[i], XmNbackground, forg);i++;
  574.         XtSetArg(args[i], XmNforeground, back);i++;
  575.       }
  576.       else{
  577.         XtSetArg(args[i], XmNforeground, forg);i++;
  578.         XtSetArg(args[i], XmNbackground, back);i++;
  579.       }
  580.       XtSetValues(YouHaveLabel[j], args, i);
  581.       SetLabel(YouHaveLabel[j], label);
  582.    }
  583.    if( whichone >= _players)
  584. #ifndef __DECCXX
  585.    throw(" The index for Table::CurrentSeat is too big. ");
  586. #else
  587.     cout << " The index for Table::CurrentSeat is too big. " << endl;
  588. #endif
  589. }
  590.  
  591. void Table::DealerDrawingAreaCB( Widget w, XtPointer client_data,
  592.                                             XmDrawingAreaCallbackStruct *call_data)
  593. {
  594. #ifndef VMS
  595.   try{
  596. #endif
  597. #ifdef DEBUG
  598.    cout << "Calling DealerDrawingAreaCB" << endl;
  599. #endif DEBUG
  600.    if (call_data->window) {
  601.      XEvent event;
  602.      Table * table = (Table*) client_data;
  603.      // drain Expose events 
  604.      while (XCheckTypedWindowEvent(XtDisplay(table->DealerDrawingArea()),
  605.             XtWindow(table->DealerDrawingArea()), Expose, &event));
  606.      XClearWindow(XtDisplay(table->DealerDrawingArea()),
  607.                         XtWindow(table->DealerDrawingArea()));
  608.      (table->_dealerFace == 0) ?
  609.      ((DealerSeat*)table->GetDealerSeat())->ShowCardsBeforeBet(table->GetDealer()) :  
  610.      table->GetDealerSeat()->ShowCards(table->GetDealer());
  611.    }
  612. #ifndef VMS
  613.  }
  614.  catch(const char *msg)
  615.  {
  616.     Table::DoExceptionDialog(msg);
  617. #ifdef DEBUG
  618.     cout << msg << endl;
  619. #endif
  620.  }
  621. #endif /* VMS */
  622. }
  623.  
  624. void Table::PlayerDrawingAreaCB( Widget w, XtPointer client_data,
  625.                                  XmDrawingAreaCallbackStruct *call_data)
  626. {
  627. #ifndef VMS
  628.   try{
  629. #endif  
  630. #ifdef DEBUG
  631.    cout << "Calling PlayerDrawingAreaCB" << endl;
  632. #endif DEBUG
  633.  
  634.    if (call_data->window) {
  635.      XEvent event; 
  636.      Table * table = (Table*) client_data; 
  637.      Dealer* dealer = table->GetDealer() ; 
  638.       // drain Expose events  
  639.      while (XCheckTypedWindowEvent(table->GetDisplay(), 
  640.             XtWindow(table->PlayerDrawingArea()), Expose, &event));
  641.      XClearWindow(XtDisplay(table->PlayerDrawingArea()), XtWindow(table->PlayerDrawingArea()));
  642.      int i = dealer->CurrentSpot();
  643.      do {
  644.         dealer->CurrentPlayer()->GetSeat()->ShowCards(dealer->CurrentPlayer());
  645.           if(!dealer->NextPlayer())
  646.              dealer->FirstPlayer();
  647.      } while(dealer->CurrentSpot() != i);
  648.    }
  649. #ifndef VMS
  650.  }
  651.  catch(const char *msg)
  652.  {
  653.     Table::DoExceptionDialog(msg);
  654. #ifdef DEBUG
  655.     cout << msg << endl;
  656. #endif
  657.  }
  658. #endif /* VMS */
  659. }
  660.  
  661. void Table::AnteScrollCB( Widget w, XtPointer client_data,
  662.                                   XmScaleCallbackStruct *call_data)
  663. {
  664. #ifdef DEBUG
  665.    cout << "Calling AnteScrollCB" << endl;
  666. #endif DEBUG
  667.    int i;
  668.    char str[80];
  669.    Arg  args[5];
  670.  
  671.    Table *table = (Table*)client_data;
  672.    table->_dealerFace = 0;
  673.    int   betPlaced = call_data->value;
  674.    Dealer * dealer = table->GetDealer();
  675.  
  676.    if(table->_minBet > (dealer->CurrentPlayer()->BankRoll()-1)/3)
  677.    {
  678.       char str[80];
  679.       sprintf(str, "Not enough money left for a bet.\nAdded another $%d!", table->
  680. _bankroll);
  681.       DoExceptionDialog(str);
  682.       dealer->CurrentPlayer()->BankRoll(table->_bankroll+
  683.                                         dealer->CurrentPlayer()->BankRoll());
  684.       sprintf(str, "$%d", dealer->CurrentPlayer()->BankRoll());
  685.       SetLabel(table->YouHaveLabelValue[dealer->CurrentSpot() -1], str);
  686.    }
  687.  
  688.    if(betPlaced > (dealer->CurrentPlayer()->BankRoll()-1)/3)
  689.    {
  690.       sprintf(str, "Not enough money either for initial ante or additional bet.");
  691.       DoExceptionDialog(str);
  692.    }
  693. }
  694.  
  695. void Table::ManageHelpRulesDialogCB( Widget w, XtPointer client_data, caddr_t call_data)
  696. {
  697.    XtManageChild(HelpRulesDialog);
  698. }
  699.  
  700. void Table::DealCB( Widget w, XtPointer client_data, caddr_t call_data)
  701. {
  702. #ifdef DEBUG
  703.    cout << "Calling DealCB" << endl;
  704. #endif DEBUG
  705.    Arg  args[5];
  706.    char str[80];
  707.     XmScaleCallbackStruct  data;
  708.    Table *table = (Table*)client_data;
  709.  
  710.    SetLabel(table->DealerTableLabel, "");
  711.    XtSetArg(args[0], XmNvalue, &(data.value));
  712.    XtGetValues(table->AnteScroll, args, 1);
  713. #ifndef VMS
  714.    try{ 
  715. #endif
  716.    int i;
  717.  
  718.    table->_dealerFace = 0;
  719.    int   betPlaced = data.value;
  720.    Dealer * dealer = table->GetDealer();
  721.    i = (int) XmToggleButtonGetState (table->ProgressiveButton);
  722.  
  723.    if(table->_minBet > (dealer->CurrentPlayer()->BankRoll()-1)/3)
  724.    {
  725.       char str[80];
  726.       sprintf(str, "Not enough money left for a bet.\nAdded another $%d!", table->
  727. _bankroll);
  728.       DoExceptionDialog(str);
  729.       dealer->CurrentPlayer()->BankRoll(table->_bankroll+
  730.                                         dealer->CurrentPlayer()->BankRoll());
  731.       sprintf(str, "$%d", dealer->CurrentPlayer()->BankRoll());
  732.       SetLabel(table->YouHaveLabelValue[dealer->CurrentSpot() -1], str);
  733.    }
  734.  
  735.    if(i != dealer->CurrentPlayer()->Progressive())
  736.        dealer->CurrentPlayer()->Progressive(i);
  737.    dealer->CurrentPlayer()->Ante(betPlaced);
  738.     sprintf(str, "$%d", dealer->CurrentPlayer()->BankRoll());
  739.     SetLabel(table->YouHaveLabelValue[dealer->CurrentSpot() -1], str);
  740.     if(dealer->NextPlayer())
  741.     {
  742.        i=0;
  743.         XtSetArg(args[i], XmNmaximum, (dealer->CurrentPlayer()->BankRoll()-1)/3);
  744.         betPlaced = (betPlaced > (dealer->CurrentPlayer()->BankRoll()-1)/3) ?
  745.                           table->_minBet : betPlaced;
  746.         XtSetArg(args[i], XmNvalue, betPlaced); i++;
  747.         XtSetValues(table->AnteScroll, args, i);
  748.          sprintf(str, "$%d", dealer->CurrentPlayer()->BankRoll());
  749.          SetLabel(table->YouHaveLabelValue[dealer->CurrentSpot() -1], str);
  750.        table->CurrentSeat(dealer->CurrentSpot() -1);
  751.     }else{
  752.          Disable( table->DealButton) ;
  753.        Disable( table->AnteScroll) ;
  754.         dealer->DealCards();
  755.        XClearWindow(XtDisplay(table->PlayerDrawingArea()), XtWindow(table->PlayerDrawingArea()));
  756.        XClearWindow(XtDisplay(table->DealerDrawingArea()), XtWindow(table->DealerDrawingArea()));
  757.          ((DealerSeat*)dealer->GetSeat())->ShowCardsBeforeBet(dealer);
  758.        dealer->FirstPlayer();
  759.          do{
  760.             dealer->CurrentPlayer()->Score();
  761.             dealer->CurrentPlayer()->GetSeat()->ShowCards(dealer->CurrentPlayer());
  762.          }while(dealer->NextPlayer());
  763.        Enable( table->BetButton ) ;
  764.        Enable( table->FoldButton) ;
  765.        dealer->FirstPlayer();
  766.        table->CurrentSeat(0);
  767.    }
  768. #ifndef VMS
  769.  }
  770.  catch(const char *msg)
  771.  {
  772.     Table::DoExceptionDialog(msg);
  773. #ifdef DEBUG
  774.     cout << msg << endl;
  775. #endif
  776.  }
  777. #endif /* VMS */
  778. }
  779.  
  780. void Table::BetCB( Widget w, XtPointer client_data, caddr_t call_data)
  781. {
  782. #ifndef VMS
  783.   try{
  784. #endif
  785. #ifdef DEBUG
  786.    cout << "Calling BetCB" << endl;
  787. #endif DEBUG
  788.    char str[80];
  789.    Arg  args[5];
  790.  
  791.    Table *table = (Table*)client_data;
  792.  
  793.    Dealer * dealer = table->GetDealer();
  794.    dealer->CurrentPlayer()->Bet(dealer->CurrentPlayer()->Ante()*2);
  795.     sprintf(str, "$%d", dealer->CurrentPlayer()->BankRoll());
  796.     SetLabel(table->YouHaveLabelValue[dealer->CurrentSpot() -1], str);
  797.     if(!dealer->NextPlayer())
  798.         PayTime(table);
  799.    else
  800.       table->CurrentSeat(dealer->CurrentSpot() -1);
  801. #ifndef VMS
  802.  }
  803.  catch(const char *msg)
  804.  {
  805.     Table::DoExceptionDialog(msg);
  806. #ifdef DEBUG
  807.     cout << msg << endl;
  808. #endif
  809.  }
  810. #endif /* VMS */
  811. }
  812.  
  813. void Table::FoldCB( Widget w, XtPointer client_data, caddr_t call_data)
  814. {
  815. #ifndef VMS
  816.   try{
  817. #endif
  818. #ifdef DEBUG
  819.    cout << "Calling FoldCB" << endl;
  820. #endif DEBUG
  821.  
  822.    char str[80];
  823.    Arg  args[5];
  824.  
  825.    Table *table = (Table*)client_data;
  826.  
  827.    Dealer * dealer = table->GetDealer();
  828.    dealer->CurrentPlayer()->Fold();
  829.    sprintf(str, "$%d", dealer->CurrentPlayer()->BankRoll());
  830.    SetLabel(table->YouHaveLabelValue[dealer->CurrentSpot() -1], str);
  831.    if(!dealer->NextPlayer())
  832.       PayTime(table);
  833.    else
  834.       table->CurrentSeat(dealer->CurrentSpot() -1);
  835. #ifndef VMS
  836.  }
  837.  catch(const char *msg)
  838.  {
  839.     Table::DoExceptionDialog(msg);
  840. #ifdef DEBUG
  841.     cout << msg << endl;
  842. #endif
  843.  }
  844. #endif /* VMS */
  845. }
  846.  
  847. void Table::PayTime(Table* table)
  848. {
  849. #ifndef VMS
  850.   try{
  851. #endif
  852. #ifdef DEBUG
  853.    cout << "Calling Table::PayTime" << endl;
  854. #endif DEBUG
  855.  
  856.    char str[80];
  857.    Arg  args[5];
  858.    Dealer *dealer = table->GetDealer();
  859.  
  860.    Disable( table->BetButton ) ;
  861.    Disable( table->FoldButton) ;
  862.    table->_dealerFace = 1;
  863.     dealer->Score();
  864.    dealer->FirstPlayer();
  865.    XClearWindow(XtDisplay(table->DealerDrawingArea()), XtWindow(table->DealerDrawingArea()));
  866.     dealer->GetSeat()->ShowCards(dealer);
  867.    if(dealer->Score() < 573496) // Does not have a King/Ace or higher
  868.    {
  869.        strcpy(str,"Dealer does not have a ACE/KING or higher.");
  870.       SetLabel(DealerTableLabel, str);
  871.    }
  872.     dealer->CollectBet();
  873.     do
  874.     {
  875.       sprintf(str, "$%d", dealer->CurrentPlayer()->BankRoll());
  876.       SetLabel(table->YouHaveLabelValue[dealer->CurrentSpot() -1], str);
  877.      if(dealer->CurrentPlayer()->WinLost() >= 0)
  878.           sprintf(str, "Won: $%d", dealer->CurrentPlayer()->WinLost());
  879.      else
  880.           sprintf(str, "Lost: $%d", -dealer->CurrentPlayer()->WinLost());
  881.       SetLabel(table->YouWinLoseValue[dealer->CurrentSpot() -1], str);
  882.     }while(dealer->NextPlayer());
  883.    
  884.    // for the first player
  885.    dealer->FirstPlayer();
  886.     int  betPlaced;
  887.    XtSetArg(args[0], XmNvalue, &betPlaced);
  888.    XtGetValues(table->AnteScroll, args, 1);
  889.    sprintf(str, "$%d", dealer->CurrentPlayer()->BankRoll());
  890.    SetLabel(table->YouHaveLabelValue[dealer->CurrentSpot() -1], str);
  891.    int i=0;
  892.    if(table->_minBet > (dealer->CurrentPlayer()->BankRoll()-1)/3)
  893.    {
  894.       char str[80];
  895.       sprintf(str, "Not enough money left for a bet.\nAdded another $%d!", table->_bankroll);
  896.       DoExceptionDialog(str);
  897.       dealer->CurrentPlayer()->BankRoll(table->_bankroll+
  898.                                         dealer->CurrentPlayer()->BankRoll());
  899.        sprintf(str, "$%d", dealer->CurrentPlayer()->BankRoll());
  900.        SetLabel(table->YouHaveLabelValue[dealer->CurrentSpot() -1], str);
  901.    }
  902.    XtSetArg(args[i], XmNmaximum, (dealer->CurrentPlayer()->BankRoll()-1)/3);
  903.  
  904.     betPlaced = (betPlaced > (dealer->CurrentPlayer()->BankRoll()-1)/3) ?
  905.                                      table->_minBet : betPlaced;
  906.    XtSetArg(args[i], XmNvalue, betPlaced); i++;
  907.    XtSetValues(table->AnteScroll, args, i);
  908.     Enable( table->DealButton) ;
  909.    Enable( table->AnteScroll) ;
  910.    dealer->NewGame();
  911.    table->CurrentSeat(0);
  912.     sprintf(str, "JACKPOT: %d", dealer->JackPot());
  913.    SetLabel(JackPotLabel, str);
  914. #ifndef VMS
  915.  }
  916.  catch(const char *msg)
  917.  {
  918.     Table::DoExceptionDialog(msg);
  919. #ifdef DEBUG
  920.     cout << msg << endl;
  921. #endif
  922.  }
  923. #endif /* VMS */
  924. }
  925.  
  926. void Table::Enable ( Widget client_data )
  927. {
  928.       XtSetSensitive (client_data, TRUE);
  929. }
  930.  
  931. void Table::Disable ( Widget client_data)
  932. {
  933.     XtSetSensitive (client_data, FALSE);
  934. }
  935.  
  936. void Table::Start()
  937. {
  938.    XtAppMainLoop (app_context);
  939. }
  940.