card.h

// Card header
// Brandon Goldfedder

#ifndef _CARD
#define _CARD

#include <assert.h>

// Represents a standard (one of 52) poker card
// Note that most operations are currently inline to ensure
      the speed
// is the same as if it were an open abstraction
class Card {
public:
   enum SUIT {HEART, DIAMOND, CLUB, SPADE };
   inline Card();
   inline Card(SUIT suit, char value);
   inline Card(const Card& card);
   inline ~Card();
   inline char CardType() const;       // return the current
      card 'A' - 'K'
   inline SUIT Suit() const;           // return the suit
   char SuitAsChar() const;            // return the suit as
      'H','D','S','C'
   inline bool SetSuit(SUIT newSuit);  // Set the suit
      (returns true if successful)
   inline bool SetType(char newType);  // Set the card type
   inline bool IsFaceCard() const;     // is it a face card
      'J','Q','K'
   inline bool IsValueCard() const;    // is it a '2' - 'T'
   inline bool IsAce() const;          // is it an ace
   inline bool IsValid() const;        // test that the card
      type is valid
   inline bool operator < (const Card& rhs) const;  // only
      based on type
   inline bool operator == (const Card& rhs) const; // checks
      both type and suit
   inline Card& operator = (const Card& rhs);
private:
   SUIT suit;
   char value;
   };
inline Card::Card():
   suit(HEART), value('A')
{
}

inline Card::Card(SUIT suit, char value) :
   suit(suit), value(value)
{
   assert (IsValid());
}

inline Card::Card(const Card& card):
   suit(card.suit), value(card.value)
{
}

inline Card::~Card()
{
}

inline char Card::CardType() const
{
   return value;
}

inline bool Card::SetSuit(SUIT newSuit)
{
   suit = newSuit;
   return true;
}

inline bool Card::SetType(char newType)
{
   value = newType;
   return IsValid();
}

inline Card::SUIT Card::Suit() const
{
   return suit;
}

inline bool Card::IsFaceCard() const
{
   return (value == 'J' || value == 'Q' || value == 'K'),
}

inline bool Card::IsValueCard() const
{
   return (value >= '2' || value <= '9' || value == 'T'),
}
inline bool Card::IsAce() const
{
   return value == 'A';
}

inline bool Card::IsValid() const
{
   return IsFaceCard() || IsValueCard() || IsAce();
}

inline bool Card::operator< (const Card& rhs) const
{
   return value < rhs.value;
}


inline bool Card::operator== (const Card& rhs) const
{
   return value == rhs.value && suit == rhs.suit;
}

inline Card& Card::operator= (const Card& rhs)
{
   if (&rhs != this) {
      value = rhs.value;
      suit = rhs.suit;
      }
   return *this;
}

#endif

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.206.244