-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfoundation.cpp
122 lines (107 loc) · 2.5 KB
/
foundation.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/**
* @file Foundation.cpp
* @author Miroslav Karpíšek
* @date 24 April 2017
* @brief Soubor obsahuje asserttesty pro jednotlive třídy.
*/
#include "foundation.h++"
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
using namespace std;
Foundation::Foundation(color color) {
_color = color;
}
bool Foundation::put(Stack stack) {
if(stack.size() != 1) {
return false;
}
else {
Card card = stack.get(0);
int rest = card.hashCode() % 10;
cout << to_string(rest);
int color_num;
switch (_color) {
case DIAMONDS:
color_num = 2;
break;
case HEARDS:
color_num = 4;
break;
case SPADES:
color_num = 1;
break;
case CLUBS:
color_num = 3;
break;
}
cout << to_string(color_num) << " "<< to_string(rest);
if(color_num == rest) {
//cout << endl;
//cout << "carta: " << to_string(card.value()) << "blaicek: " << _fond.size();
//cout << endl << card.toString();
if(card.value() == (int)_fond.size() + 1) {
_fond.push_back(card);
return true;
}
}
else {
return false;
}
return false;
}
}
bool Foundation::put(Card card) {
int rest = card.hashCode() % 10;
int color_num;
switch (_color) {
case DIAMONDS:
color_num = 2;
break;
case HEARDS:
color_num = 4;
break;
case SPADES:
color_num = 1;
break;
case CLUBS:
color_num = 3;
break;
}
if(color_num == rest) {
if(card.value() == (int)_fond.size() + 1) {
_fond.push_back(card);
return true;
}
}
else {
return false;
}
return false;
}
unsigned int Foundation::size() {
return _fond.size();
}
string Foundation::toString() {
string output;
for(int i = 0; i < (int)_fond.size(); i++) {
output += _fond.at(i).toSave();
output += ",";
}
return output;
}
Card Foundation::onTop() {
if(_fond.empty()) {
Card *card = new Card(0,DIAMONDS);
return *card;
}
return _fond.back();
}
color Foundation::myColor() {
return _color;
}
bool Foundation::empty() {
return _fond.empty();
}