home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 May / Pcwk5b98.iso / Borland / Cplus45 / BC45 / BLAKJAK.PAK / BLAKJACK.H < prev    next >
C/C++ Source or Header  |  1995-08-29  |  6KB  |  240 lines

  1. //-----------------------------------------------------------------------------
  2. // Borland International.
  3. // (c) Copyright 1995.
  4. // Blakjack.h
  5. //-----------------------------------------------------------------------------
  6.  
  7. #ifndef __BLACKJACK_H
  8. #define __BLACKJACK_H
  9.  
  10. #include <owl\owlpch.h>
  11. #include <owl\applicat.h>
  12. #include <owl\dc.h>
  13. #include <owl\dialog.h>
  14. #include <owl\button.h>
  15. #include <owl\static.h>
  16. #include <owl\inputdia.h>
  17. #include <owl\validate.h>
  18. #include <owl\framewin.h>
  19. #include <owl\vbxctl.h>
  20. #include <stdio.h>
  21. #include "card.rh"
  22. #include "mhcd2001.h"
  23.  
  24. #define DEALER_VBX_CARD1_X 300
  25. #define DEALER_VBX_CARD1_Y 1300
  26. #define PLAYER_VBX_CARD1_X 300
  27. #define PLAYER_VBX_CARD1_Y 3800
  28.  
  29. #define VBX_CARD_WIDTH     41
  30. #define VBX_CARD_LENGTH    59
  31.  
  32. // These are the win status.
  33. #define PLAYER  1
  34. #define DEALER  2
  35. #define BOTH    3
  36. #define UNKNOWN 4
  37.  
  38. // VBX card control class.
  39. class TVbxMhCardDeck;
  40. class TBlackjack;
  41.  
  42. class Card
  43. {
  44.     private:
  45.         int number;    // Ace->0, Two->1..., Jack->10, King->11, Queen->12
  46.         int type;      // HEARTS, CLUBS, DIAMONDS, SPADE
  47.         int face;      // 1 -> face up, 0 -> face down.
  48.         int mark;      // This is used to keep track of ACE value(1(0) or 11(1))
  49.         int pVBXCard;  // this contains the index+1 of the VBX card in the VBX array
  50.                             // in TBlackjack class, in OwlMain.
  51.     public:
  52.                 Card(int val, int type, int faceUp);
  53.                 ~Card()
  54.                 {
  55.                         pVBXCard = 0;
  56.                 }
  57.  
  58.         int    setNumber (int i);
  59.         int     getNumber () const
  60.                 {
  61.                     return number;
  62.                 }
  63.         int     setType(int i);
  64.         int    getType() const
  65.                 {
  66.                         return type;
  67.                 }
  68.         // Marks the card as faceup
  69.         void     up()
  70.                 {
  71.                     face = 1;
  72.                 }
  73.         // Marks the card as face down.
  74.         void     down()
  75.                 {
  76.                     face = 0;
  77.                 }
  78.         int    isUp      () const;
  79.         void     flip      ();
  80.         void     setMark     (int i);
  81.  
  82.         int     getMark() const
  83.                 {
  84.                     return mark;
  85.                 }
  86.  
  87.         int    isMarked() const;
  88.         int     getVBXCard() const
  89.                 {
  90.                     return pVBXCard;
  91.                 }
  92.         void     setVBXCard(int );
  93.  
  94. };
  95. class Deck
  96. {
  97.     private:
  98.         int   total;       // Total number of cards in the deck
  99.                                  // Dealt cards are not in the deck.
  100.         Card    **ppCards;   // Array of cards(52) in the deck.
  101.         //Card    *pTop;       // May point to the top most card on the deck
  102.         int      topIndex;    // array index of the top most card in the deck.
  103.  
  104.     public:
  105.         int   GetTotal    () const;  // returns total number of cards in the deck.
  106.         void  SetTotal    (int i)throw (const char* ); // sets new total after a
  107.                                              // a card is dealt.
  108.         void  SetTopIndex (int );   // Sets new top index after a card is dealt.
  109.         Card  *GetCard       ();       // gets the top most card on the deck.
  110.         int   Shuffle     ();       // Shuffles all the cards on the deck.
  111.  
  112.                 Deck()throw(const char *);
  113.               ~Deck();
  114.  
  115.         friend ostream& operator<<(ostream &str, Deck& rhs);
  116. };
  117. // Prints out the Deck information. Only used to debug.
  118. ostream& operator<<(ostream &str, Deck& rhs);
  119.  
  120. class Hand
  121. {
  122.     private:
  123.         Card  **ppCards;  //Cards dealt to the hand resides in this array.
  124.         int   totalCards; //total number of cards dealt to hand.
  125.         int     points;     //total points in a game, resulting from above cards.
  126.         int     result;        // WIN, LOOSE, NONE
  127.         int     betMoney;   //stores the current bet money.
  128.  
  129.         //adjusts the ACE value from 11 to 1 if the total goes over 21.
  130.         void  AdjustAceValueIfTotalIs21Plus();
  131.  
  132.     public:
  133.       // returns the pointer to the array of cards.
  134.         Card  **getCards   () const {return ppCards;};
  135.  
  136.         int   AddCard      (Card *pCard); // Adds the dealt card to the array.
  137.         void  setPoints    (int i);
  138.         int   getPoints    () const;
  139.         void  setResult    (int i);
  140.         int   getResult    () const;
  141.         int   setBetMoney  (int i);
  142.         int   getBetMoney  () const;
  143.         int   getTotalCards() const;
  144.         int   incTotalCards();
  145.         int   flushCards   (); // Flushes all the cards from the hand.
  146.  
  147.         // calculate the points for the hand when a new card is drawn.
  148.         // Rule , make Ace = 11 if (total points =< 10) else 1
  149.         int   calcPoints   (int number) throw(const char*);
  150.  
  151.                 Hand()throw (const char *);
  152.               ~Hand();
  153.  
  154.         friend ostream& operator << (ostream& , Hand &h);
  155. };
  156. ostream& operator << (ostream& , Hand &h); // only used for debugging purposes
  157.  
  158. class Bankroll
  159. {
  160.     private:
  161.         int    total;     // Stores the current bankroll amount.
  162.  
  163.     public:
  164.                 Bankroll   (int i);
  165.                 ~Bankroll  ();
  166.  
  167.         void     setTotal   (int i); //Sets "total" to input value
  168.         int     getTotal   () const;      //Gets the "total" value
  169.         // retlurns 0 if input > total
  170.         int     decrementBy(int i); //decrements the total by specified amount.
  171.         int     incrementBy(int i)throw(const char *); //increments the total
  172.                                                                     //by specified amount.
  173.         int     isEmpty    () const;      // Checks for 0 bankroll
  174.  
  175. };
  176. class Dealer;
  177. class Player: public Hand
  178. {
  179.     private:
  180.         Bankroll        pocket;
  181.  
  182.     public:
  183.         Bankroll & getPocket() { return pocket;}
  184.         int    Bet  (int i);
  185.         int     Lost () throw(const char *);  // Registers loss
  186.         int    Won  ();                      // Registers win
  187.  
  188.                 Player(int money);
  189.                 ~Player();
  190.  
  191.         friend operator << (Player &p, Dealer &d)throw(const char *);
  192.         friend Dealer& operator << (Dealer &p, Dealer &d)throw(const char *);
  193.  
  194. };
  195.  
  196. class Dealer:public Hand
  197. {
  198.     private:
  199.         Deck    *deck;
  200.  
  201.     public:
  202.         int    dealACard();
  203.         Deck     &getDeck () const;
  204.         void     setDeck  (Deck *p);
  205.                 Dealer   ();
  206.                 ~Dealer  ();
  207.  
  208.         friend operator << (Player &p, Dealer &d)throw(const char *);
  209.         friend Dealer& operator << (Dealer &p, Dealer &d)throw(const char *);
  210.         friend ostream& operator << (ostream& , Dealer &d);
  211.  
  212. };
  213.  
  214. ostream& operator << (ostream& , Dealer &d);
  215. operator << (Player &p, Dealer &d) throw(const char *);
  216.  
  217. class Blackjack
  218. {
  219.     private:
  220.         Dealer    dealer;
  221.         Player    **ppPlayer;
  222.  
  223.     public:
  224.         Dealer    &getDealer ()
  225.         {
  226.                 return dealer;
  227.         }
  228.         Player    *getPlayer (int p) const;
  229.         int         IsBlackjack();
  230.  
  231.         // PLAYER, DEALER, BOTH
  232.         int         whoLost ();
  233.  
  234.                     Blackjack ();
  235.                     Blackjack (int numberOfPlayer);
  236.                     ~Blackjack();
  237. };
  238.  
  239. #endif
  240.