-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcard.cpp
More file actions
84 lines (68 loc) · 1.56 KB
/
card.cpp
File metadata and controls
84 lines (68 loc) · 1.56 KB
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
//
// Created by willworthington on 11/4/2018.
//
#include <iostream>
#include "card.h"
using namespace std;
// default, ace of spades
Card::Card(){
myRank = 1;
mySuit = spades;
}
Card::Card(int rank, Suit s){
myRank = rank;
mySuit = s;
}
/*
//Sets the rank
void Card::setRank(const int& rank){
myRank = rank;
}
void Card::setSuit(const Suit& s){
mySuit = s;
}*/
// return string version e.g. Ac 4h Js
string Card::toString()const{
return (rankString(myRank)+suitString(mySuit));
}
// true if suit same as c
bool Card::sameSuitAs(const Card& c) const{
return (mySuit==c.mySuit);
}
// return rank, 1..13
int Card::getRank() const{
return myRank;
}
// return "s", "h",...
string Card::suitString(Suit s) const{
switch (s){
case spades: return "s";
case hearts: return "h";
case diamonds: return "d";
case clubs: return "c";
}
}
// return "A", "2", ..."Q"
string Card::rankString(int r) const{
switch (r){
case 1: return "A";
case 2: return "2";
case 3: return "3";
case 4: return "4";
case 5: return "5";
case 6: return "6";
case 7: return "7";
case 8: return "8";
case 9: return "9";
case 10: return "10";
case 11: return "J";
case 12: return "Q";
case 13: return "K";
}
}
bool Card::operator == (const Card& rhs) const{
return ((myRank==rhs.myRank)&&(mySuit==rhs.mySuit));
}
bool Card::operator != (const Card& rhs) const{
return !((myRank==rhs.myRank)&&(mySuit==rhs.mySuit));
}