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>
26 #include "Card.h"
27
28 using namespace std;
29
30 //## Constructors
31
Card(int CardIndex)32 Card::Card(int CardIndex)
33 {
34 if(CardIndex >=54 || CardIndex < 0)
35 {
36 cout << " Card Index " << CardIndex << "Out of Range" << endl;
37 throw ( " Card index out of range. " );
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
Card(char Suit,char Rank)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 throw ( "Suit, Rank combination does not exist" );
80 }
81 }
82
~Card()83 Card::~Card(){}
84
ShowFront() const85 void Card::ShowFront() const
86 {
87 #ifdef DEBUG
88 cout << _suit << (int) _rank << ' ';
89 #endif
90 }
91
ShowBack() const92 void Card::ShowBack() const
93 {
94 #ifdef DEBUG
95 cout << "XX ";
96 #endif
97 }
98
99