-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCard.cpp
106 lines (85 loc) · 2.82 KB
/
Card.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*------------------------------------------------------------------------------------------------------------------------------------------
Simple Card game Class Card
Card.cpp
Written for summer course in c++
2014 Anna Dunblad
------------------------------------------------------------------------------------------------------------------------------------------*/
#include "Card.h"
#include <iostream> //input/output
/**----------------------------------------------------------
Constructor to create and initialize empty card
----------------------------------------------------------------**/
Card::Card(){
suit=0;
rank=0;
}
/**----------------------------------------------------------
set rank and suit of card
----------------------------------------------------------------**/
void Card::setData(int _suit, int _rank){
rank=_rank;
suit=_suit;
}
/**----------------------------------------------------------
return rank of card
----------------------------------------------------------------**/
int Card::getRank(){
return rank;
}
/**----------------------------------------------------------
print a card
----------------------------------------------------------------**/
void Card::printCard(int printMethod){
const char* suitForPrint;
rank=this->rank;
switch(this->suit)
{
case 1:
suitForPrint = "\x06"; //♠
break;
case 2:
suitForPrint = "\x03"; //♥
break;
case 3:
suitForPrint = "\x04"; //♦
break;
case 4:
suitForPrint = "\x05"; //♣
break;
default:
suitForPrint = " ";
break;
}
if(printMethod==1){
std::cout<<"----------------------"<<std::endl;
std::cout<<"|"<<rank<<" |"<<std::endl;
std::cout<<"|"<<*suitForPrint<<" |"<<std::endl;
std::cout<<"| |"<<std::endl;
std::cout<<"| |"<<std::endl;
std::cout<<"| "<<*suitForPrint<<" |"<<std::endl;
std::cout<<"| |"<<std::endl;
std::cout<<"| |"<<std::endl;
std::cout<<"| |"<<std::endl;
std::cout<<"| "<<rank<<"|"<<std::endl;
std::cout<<"| "<<*suitForPrint<<"|"<<std::endl;
std::cout<<"----------------------"<<std::endl;
}
else{
switch(this->rank){
case 1:
std::cout<<"Ace of "<<*suitForPrint<<std::endl;
break;
case 11:
std::cout<<"Jack of "<<*suitForPrint<<std::endl;
break;
case 12:
std::cout<<"Queen of "<<*suitForPrint<<std::endl;
break;
case 13:
std::cout<<"King of "<<*suitForPrint<<std::endl;
break;
default:
std::cout<<rank<<" of "<<*suitForPrint<<std::endl;
}
}
}