Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

card.h

Go to the documentation of this file.
00001 //
00002 //  CardLib - Card class
00003 //
00004 //  Freeware
00005 //  Copyright J Brown 2001
00006 //
00007 
00008 #ifndef _CARD_INCLUDED
00009 #define _CARD_INCLUDED
00010 
00011 enum eSuit  { Clubs = 0, Diamonds = 1, Hearts = 2, Spades = 3 };
00012 enum eValue { Ace = 1, Two = 2, Three = 3, Four = 4, Five = 5, Six = 6, Seven = 7, 
00013               Eight = 8, Nine = 9, Ten = 10, Jack = 11, Queen = 12, King = 13 };
00014 
00015 inline int MAKE_CARD(int Value, int Suit)
00016 {
00017     if(Value < 1)   Value = 1;
00018     if(Value == 14) Value = 1;
00019     if(Value >  13) Value = 13;
00020 
00021     if(Suit < 0)    Suit = 0;
00022     if(Suit > 3)    Suit = 3;
00023 
00024     return ((Value - 1) * 4 + Suit);
00025 }
00026 
00027 class Card
00028 {
00029     friend class CardStack;
00030 
00031 public:
00032 
00033     Card() 
00034     { 
00035         nValue = 0;     //ace of spades by default
00036         fFaceUp = true; 
00037     }
00038     
00039     Card(int value, int suit)   //specify a face value [1-13] and suit [0-3]
00040     { 
00041         nValue = MAKE_CARD(value, suit);
00042         fFaceUp = true; 
00043     }
00044     
00045     Card(int index)             //specify a 0-51 index
00046     { 
00047         if(index < 0)  index = 0;
00048         if(index > 51) index = 51;
00049 
00050         nValue = index; 
00051         fFaceUp = true;
00052     }
00053     
00054     int Suit() const
00055     { 
00056         return (nValue % 4); 
00057     }
00058 
00059     int LoVal() const
00060     { 
00061         return (nValue / 4) + 1; 
00062     }
00063 
00064     int HiVal() const
00065     { 
00066         return ((nValue < 4) ? 14 : (nValue / 4) + 1); 
00067     }
00068 
00069     int Idx() const //unique value (0-51 etc)
00070     {
00071         return nValue;
00072     }
00073 
00074     bool FaceUp() const
00075     {
00076         return fFaceUp;
00077     }
00078     
00079     bool FaceDown() const
00080     {
00081         return !fFaceUp;
00082     }
00083 
00084     void SetFaceUp(bool fTrue)
00085     {
00086         fFaceUp = fTrue;
00087     }
00088 
00089     bool IsBlack() const
00090     {
00091         return Suit() == 0 || Suit() == 3;
00092     }
00093 
00094     bool IsRed() const
00095     {
00096         return !IsBlack();
00097     }
00098 
00099 private:
00100 
00101     int  nValue;
00102     bool fFaceUp;
00103 };
00104 
00105 #endif

Generated on Thu Feb 9 04:59:24 2012 for ReactOS by doxygen 1.6.3

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.