-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFoundation.cpp
More file actions
68 lines (61 loc) · 1.89 KB
/
Foundation.cpp
File metadata and controls
68 lines (61 loc) · 1.89 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
#include "Foundation.h"
void Foundation::createFoundation() {
pFoundationList = foundationList;
*(pFoundationList + 0) = "H00";
*(pFoundationList + 1) = "D00";
*(pFoundationList + 2) = "S00";
*(pFoundationList + 3) = "C00";
}
bool Foundation::addCard(string cardName) {
for(int index=0; index < 4; index++){
if(cardName.substr(0, 1) == (*(pFoundationList + index)).substr(0,1)){
if(stoi(cardName.substr(1, 2)) == stoi((*(pFoundationList + index)).substr(1,2))+1) {
*(pFoundationList + index) = cardName;
return true;
}
}
}
return false;
}
void Foundation::removeCard(int foundationNum){
string cardName;
if(!checkEmpty(foundationNum)) {
string cardType = foundationList[foundationNum].substr(0, 1);
int cardNum = atoi(foundationList[foundationNum].substr(1, 2).c_str()) - 1;
if (cardNum >= 10) {
cardName = cardType + to_string(cardNum);
} else {
cardName = cardType + "0" + to_string(cardNum);
}
foundationList[foundationNum] = cardName;
}
}
bool Foundation::checkEmpty(int foundationNum){
if(foundationList[foundationNum].substr(1,2) == "00"){
return true;
}
return false;
}
bool Foundation::checkWin() {
int counter =0;
for(int index=0; index<4; index++){
if(foundationList[index].substr(1,2) == "13"){
counter++;
}
}
if(counter==4){
return true;
}
return false;
}
void Foundation::printFoundation(ofstream* output) {
for(int index=0; index < 4; index++){
if(atoi((*(pFoundationList + index)).substr(1,2).c_str()) != 0){
*output << (*(pFoundationList + index)) << " ";
}
else{
*output << "___ ";
}
}
*output << endl;
}