-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayerBase.h
190 lines (155 loc) · 3.46 KB
/
PlayerBase.h
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#ifndef _PLAYER_
#define _PLAYER_
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <ctime>
#include <random>
using namespace std;
template <typename T>
class PlayerBase
{
protected:
string name;
int cash;
vector<int> depCards;
vector<T> attackCards;
public:
PlayerBase();
PlayerBase(string _name);
PlayerBase(const PlayerBase &p);
void SetName(string _name);
string GetName();
void AddDependentCards(int cards);
void AddOneDependentCard();
int SumDependentCards();
bool SetDepCards();
void SetCash(int _cash);
int GetCash();
void AddCash(int _cash);
T SumAttackCards();
T SumCards();
virtual void AddOneCard(){};
virtual void AddAttackCards(int cards){};
virtual ~PlayerBase();
PlayerBase<T> &operator=(const PlayerBase<T> &p);
bool operator==(const PlayerBase<T> &p);
bool operator<(const PlayerBase<T> &p);
bool operator>(const PlayerBase<T> &p);
void operator>>(double amount);
void operator<<(double amount);
};
template <typename T>
PlayerBase<T>::~PlayerBase()
{
}
template <typename T>
bool PlayerBase<T>::operator==(const PlayerBase<T> &p)
{
return this->SumCards() == p.SumCards();
}
template <typename T>
bool PlayerBase<T>::operator<(const PlayerBase<T> &p)
{
return this->SumCards() < p.SumCards();
}
template <typename T>
bool PlayerBase<T>::operator>(const PlayerBase<T> &p)
{
return this->SumCards() > p.SumCards();
}
template <typename T>
void PlayerBase<T>::operator>>(double amount)
{
this->cash -= static_cast<int>(amount);
}
template <typename T>
void PlayerBase<T>::operator<<(double amount)
{
this->cash += static_cast<int>(amount);
}
template <typename T>
T PlayerBase<T>::SumAttackCards()
{
return accumulate(attackCards.begin(), attackCards.end(), static_cast<T>(0));
}
template <typename T>
T PlayerBase<T>::SumCards()
{
T num1 = accumulate(attackCards.begin(), attackCards.end(), static_cast<T>(0));
T num2 = accumulate(depCards.begin(), depCards.end(), static_cast<int>(0));
return num1 - num2;
}
template <typename T>
void PlayerBase<T>::AddOneDependentCard()
{
int x = (rand() % 5) + 1;
depCards.push_back(x);
}
template <typename T>
PlayerBase<T>::PlayerBase()
{
name = "";
cash = 1000;
}
template <typename T>
PlayerBase<T>::PlayerBase(string _name)
{
name = _name;
cash = 1000;
}
template <typename T>
PlayerBase<T>::PlayerBase(const PlayerBase &p)
{
name = p.name;
copy(p.depCards.begin(), p.depCards.end(), back_inserter(depCards));
cash = p.cash;
}
template <typename T>
void PlayerBase<T>::SetName(string _name)
{
name = _name;
}
template <typename T>
string PlayerBase<T>::GetName()
{
return name;
}
template <typename T>
void PlayerBase<T>::AddDependentCards(int cards)
{
depCards.clear();
cout << "The dependent cards are" << endl;
for (int i = 0; i < cards; i++)
{
int x = (rand() % 5) + 1;
depCards.push_back(x);
}
}
template <typename T>
int PlayerBase<T>::SumDependentCards()
{
return accumulate(depCards.begin(), depCards.end(), static_cast<int>(0));
}
template <typename T>
bool PlayerBase<T>::SetDepCards()
{
return !depCards.empty();
}
template <typename T>
void PlayerBase<T>::SetCash(int _cash)
{
cash = _cash;
}
template <typename T>
int PlayerBase<T>::GetCash()
{
return cash;
}
template <typename T>
void PlayerBase<T>::AddCash(int _cash)
{
cash += _cash;
}
#endif