home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / gamtlk11.zip / source.zip / BJCPP / BLACKJACK.CPP < prev    next >
C/C++ Source or Header  |  1999-06-11  |  5KB  |  148 lines

  1. //
  2. // File: Blackjack.CPP
  3. //
  4. // Main source file for Blackjack for the Compulsive Gambler's Toolkit
  5. //
  6. #include <icoordsy.hpp>
  7. #include <iframe.hpp>
  8. #include <iapp.hpp>
  9. #include <imenubar.hpp>
  10. #include <ipoint.hpp>
  11. #include <idrawcv.hpp>
  12. #include <icolor.hpp>
  13. #include <ipushbut.hpp>
  14. #include <imsgbox.hpp>
  15. #include <ireslib.hpp>
  16. #include "Blackjack.HPP"
  17. #include "Blackjack.H"
  18.  
  19. int main()
  20. {
  21.    ICoordinateSystem::setApplicationOrientation(ICoordinateSystem::kOriginLowerLeft);
  22.    BJACK *Blackjack;
  23.    try
  24.    {
  25.          Blackjack=new(BJACK)(MainWindow);
  26.    } catch(...)
  27.    {
  28.       IMessageBox messageBox((IWindow*)0);
  29.       messageBox.setTitle(IApplication::current().userResourceLibrary().loadString(PMT_ERROR));
  30.       messageBox.show(IApplication::current().userResourceLibrary().loadString(PMT_NOLIBRARY), IMessageBox::applicationModal | IMessageBox::cancelButton | IMessageBox::moveable);
  31.       return 0;
  32.    };
  33.    IApplication::current().run();
  34.    return 0;
  35. }
  36.  
  37. //
  38. // BJACK::BJACK(const unsigned long windowId)
  39. //
  40. // Constructor for BJACK window
  41. //
  42. BJACK::BJACK(const unsigned long windowId) : IFrameWindow(IFrameWindow::defaultStyle()
  43.    | IFrameWindow::minimizedIcon, windowId),
  44.    menuBar(windowId, this),
  45.    commandHandler(this),
  46.    resizeHandler(this),
  47.    drawCanvas(MainClient, this, this),
  48.    dealButton(BTN_DEAL, this, this),
  49.    hitButton(BTN_HIT, this, this, IRectangle(0,0), IPushButton::defaultStyle() | IPushButton::disabled),
  50.    standButton(BTN_STAND, this, this, IRectangle(0,0), IPushButton::defaultStyle() | IPushButton::disabled),
  51.    splitButton(BTN_SPLIT, this, this, IRectangle(0,0), IPushButton::defaultStyle() | IPushButton::disabled),
  52.    doubleButton(BTN_DOUBLE, this, this, IRectangle(0,0), IPushButton::defaultStyle() | IPushButton::disabled),
  53.    wagerEntry(SPN_WAGER, this, this),
  54.    shoe(this),
  55.    profile()
  56. {
  57.    setClient(&drawCanvas);
  58.    drawCanvas.setBackgroundColor(IColor(IColor::kDarkGreen));
  59.    dealButton.setText(PMT_DEAL);
  60.    hitButton.setText(PMT_HIT);
  61.    standButton.setText(PMT_STAND);
  62.    doubleButton.setText(PMT_DOUBLE);
  63.    splitButton.setText(PMT_SPLIT);
  64.    try
  65.    {
  66.       wagerEntry.setRange(IRange(MIN_WAGER, MAX_WAGER));
  67.    } catch(...) {};
  68.    wagerEntry.setValue(profile.Wager);
  69.    commandHandler.handleEventsFor(this);
  70.    resizeHandler.handleEventsFor(this);
  71.    sizeTo(profile.Size);
  72.    moveTo(profile.Position);
  73.    setFocus();
  74.    show();
  75. }
  76.  
  77. //
  78. // BJACK::getPosition()
  79. //
  80. BJACK::getPosition()
  81. {
  82.    profile.Position=position();
  83.    profile.Size=size();
  84.    profile.Wager=wagerEntry.value();
  85.  
  86.    return 0;
  87. }
  88.  
  89. //
  90. // bool BJACK::deal()
  91. //
  92. // Deals a new hand
  93. //
  94. bool BJACK::deal()
  95. {
  96.    // Disable deal button
  97.    dealButton.disable();
  98.  
  99.    // Check to see if shoe needs shuffling
  100.    if(shoe.pastMarker()) shoe.shuffle();
  101.  
  102.    // Get wager stored in spin field
  103.    profile.Wager=wagerEntry.value();
  104.  
  105.    dealer.startHand();
  106.    player.newHand(profile.Wager);
  107.  
  108.    // Add cards
  109.    player.addCard(shoe.drawCard());
  110.    dealer.addCard(shoe.drawCard());
  111.    player.addCard(shoe.drawCard());
  112.    dealer.addCard(shoe.drawCard());
  113.  
  114.    return true;
  115. }
  116.  
  117. //
  118. // BJACK::~BJACK()
  119. //
  120. // Destructor for BJACK
  121. //
  122. BJACK::~BJACK()
  123. {
  124.    // Get size and position of window for profile saving
  125.    commandHandler.stopHandlingEventsFor(this);
  126. }
  127.  
  128. //
  129. // BJACK::sizeClient(IResizeEvent& resizeEvent)
  130. //
  131. // Called whenever the client window is resized
  132. //
  133. bool BJACK::sizeClient(IResizeEvent& resizeEvent)
  134. {
  135.    dealButton.moveTo(IPoint(DEAL_XPOS*resizeEvent.newSize().width(), DEAL_YPOS*resizeEvent.newSize().height()));
  136.    dealButton.sizeTo(ISize(BUTTON_XSIZE*resizeEvent.newSize().width(), BUTTON_YSIZE*resizeEvent.newSize().height()));
  137.    hitButton.moveTo(IPoint(HIT_XPOS*resizeEvent.newSize().width(), HIT_YPOS*resizeEvent.newSize().height()));
  138.    hitButton.sizeTo(ISize(BUTTON_XSIZE*resizeEvent.newSize().width(), BUTTON_YSIZE*resizeEvent.newSize().height()));
  139.    standButton.moveTo(IPoint(STAND_XPOS*resizeEvent.newSize().width(), STAND_YPOS*resizeEvent.newSize().height()));
  140.    standButton.sizeTo(ISize(BUTTON_XSIZE*resizeEvent.newSize().width(), BUTTON_YSIZE*resizeEvent.newSize().height()));
  141.    doubleButton.moveTo(IPoint(DOUBLE_XPOS*resizeEvent.newSize().width(), DOUBLE_YPOS*resizeEvent.newSize().height()));
  142.    doubleButton.sizeTo(ISize(BUTTON_XSIZE*resizeEvent.newSize().width(), BUTTON_YSIZE*resizeEvent.newSize().height()));
  143.    splitButton.moveTo(IPoint(SPLIT_XPOS*resizeEvent.newSize().width(), SPLIT_YPOS*resizeEvent.newSize().height()));
  144.    splitButton.sizeTo(ISize(BUTTON_XSIZE*resizeEvent.newSize().width(), BUTTON_YSIZE*resizeEvent.newSize().height()));
  145.    wagerEntry.moveTo(IPoint(WAGERENTRY_XPOS*resizeEvent.newSize().width(), WAGERENTRY_YPOS*resizeEvent.newSize().height()));
  146.    wagerEntry.sizeTo(ISize(WAGERENTRY_XSIZE*resizeEvent.newSize().width(), wagerEntry.size().height()));
  147.    return true;
  148. }