home *** CD-ROM | disk | FTP | other *** search
/ vsiftp.vmssoftware.com / VSIPUBLIC@vsiftp.vmssoftware.com.tar / FREEWARE / FREEWARE40.ZIP / caribbeanstud / card.cpp < prev    next >
C/C++ Source or Header  |  1997-02-08  |  2KB  |  101 lines

  1. /*
  2.  * (c) Copyright 1997, Qun Zhang.
  3.  *
  4.  * Permission to use, copy, modify, distribute, and sell this software
  5.  * and its documentation for any purpose is hereby granted without fee,
  6.  * provided that the above copyright notice appear in all copies and
  7.  * that both that copyright notice and this permission notice appear in
  8.  * supporting documentation, and that the name of Qun Zhang not be used
  9.  * in advertising or publicity pertaining to distribution of the software
  10.  * without specific, written prior permission.  Qun Zhang make no
  11.  * representations about the suitability of this software for any purpose.
  12.  * It is provided "as is" without express or implied warranty.
  13.  *
  14.  * THE ABOVE-NAMED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  15.  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  16.  * EVENT SHALL THE ABOVE-NAMED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  17.  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  18.  * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  19.  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  20.  * PERFORMANCE OF THIS SOFTWARE.
  21.  *
  22.  */
  23.  
  24. // Card
  25. #include <iostream.h>
  26. #include "Card.h"
  27.  
  28. //## Constructors
  29.  
  30. Card::Card(int CardIndex)
  31. {
  32.       if(CardIndex >=54 || CardIndex < 0)
  33.       {
  34.          cout << " Card Index " << CardIndex << "Out of Range" << endl;
  35. #ifndef __DECCXX
  36.          throw ( " Card index out of range. " );
  37. #endif
  38.       }
  39.       if(CardIndex >=52 ){
  40.          _suit = 'W';
  41.          _rank = CardIndex - 52;
  42.       }
  43.       else
  44.       {
  45.          switch(CardIndex/13){
  46.          case 0:
  47.              _suit = 'C';
  48.           break;
  49.          case 1:
  50.              _suit = 'D';
  51.           break;
  52.          case 2:
  53.              _suit = 'H';
  54.           break;
  55.          case 3:
  56.              _suit = 'S';
  57.        }
  58.        _rank = CardIndex % 13 +2;
  59.      }
  60. }
  61.  
  62. Card::Card(char Suit, char Rank)
  63. {
  64.     if(Suit == 'W'){
  65.       _suit = Suit; _rank = 0;
  66.    }
  67.    else if ( Rank >=1 && Rank <= 14 &&
  68.                  ( Suit == 'C' ||
  69.                     Suit == 'D' ||
  70.                     Suit == 'H' ||
  71.                     Suit == 'S' ) )
  72.    {
  73.         _suit = Suit;
  74.         _rank = Rank == 1 ? 14 : Rank;
  75.     }
  76.    else
  77.     {
  78.         cout << "Suit " << Suit << " Rank " << (int) Rank << " not Valid " << endl;
  79. #ifndef __DECCXX
  80.         throw ( "Suit, Rank combination does not exist" );
  81. #endif
  82.    }
  83. }
  84.  
  85. Card::~Card(){}
  86.  
  87. void Card::ShowFront() const
  88. {
  89. #ifdef DEBUG
  90.    cout << _suit << (int) _rank << ' ';
  91. #endif
  92. }
  93.  
  94. void Card::ShowBack() const
  95. {
  96. #ifdef DEBUG
  97.    cout << "XX ";
  98. #endif
  99. }
  100.  
  101.