home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / BLAKJACK.PAK / BLAKJACK.H < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  5.9 KB  |  221 lines

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