-
Notifications
You must be signed in to change notification settings - Fork 0
/
reward.cpp
59 lines (45 loc) · 1.77 KB
/
reward.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
#include "reward.h"
#include "rewarddeck.h"
#include <cassert>
//#define TEST_REWARD
Reward::Reward(const int &nRubies) {
if (nRubies >= 1 && nRubies <= 4) _nRubies = nRubies;
else throw out_of_range("Error Initializing Reward: Rubies must be only 1 to 4! ");
}
Reward::Reward(const Reward &reward) = default;
Reward &Reward::operator=(const Reward &reward) {
if (this != &reward) this->_nRubies = reward.getNRubies();
return (*this);
}
int Reward::getNRubies() const { return _nRubies; }
ostream &operator<<(ostream &os, const Reward &reward) {
return (os << "Reward has " << reward.getNRubies() << (reward.getNRubies() > 1 ? " Rubies" : " Ruby"));
}
bool operator<(const Reward &r1, const Reward &r2) { return r1.getNRubies() < r2.getNRubies(); }
bool operator>(const Reward &r1, const Reward &r2) { return r1.getNRubies() > r2.getNRubies(); }
bool operator==(const Reward &r1, const Reward &r2) { return r1.getNRubies() == r2.getNRubies(); }
Reward &Reward::operator=(const int &nRubiesOther) {
if (nRubiesOther >= 1 && nRubiesOther <= 4) _nRubies = nRubiesOther;
else throw out_of_range("Error Equal Assignment Reward from int: Rubies must be only 1 to 4! ");
return *this;
}
Reward::operator int() { return getNRubies(); }
#ifdef TEST_REWARD
int main() {
cout<<"TEST_REWARD"<<endl;
RewardDeck& r = RewardDeck::make_RewardDeck();
Reward* reward = r.getNext();
Reward* reward2 = r.getNext();
for(int i = 0;i<6;i++){
if(*reward>*reward2){
assert(*reward>*reward2);
}else if(*reward<*reward2){
assert(*reward<*reward2);
}else{
assert(*reward == *reward2);
}
cout<<"Reward Value "<<reward2->getNRubies()<<endl;
reward2 = r.getNext();
}
}
#endif // TEST_REWARD