-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCard.cpp
245 lines (205 loc) · 5.16 KB
/
Card.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
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
//
// Card.cpp
// Cards
//
// Created by Sisir Potluri on 6/3/20.
// Copyright © 2020 Sisir Potluri. All rights reserved.
//
#include <cassert>
#include <iostream>
#include <string>
#include "Card.h"
using namespace std;
constexpr const char* const Card::PYRO;
constexpr const char* const Card::AERO;
constexpr const char* const Card::AQUA;
constexpr const char* const Card::EARTH;
constexpr const char* const Card::SPECTRAL;
constexpr const char* const Card::GLEAM;
constexpr const char* const Card::GRIFFIN;
constexpr const char* const Card::PHOENIX;
constexpr const char* const Card::LEVIATHAN;
constexpr const char* const Card::DJINN;
Card::Card() : element(PYRO), form(PHOENIX), health(100) {}
Card::Card(const std::string &element_in, const std::string &form_in)
: element(element_in), form(form_in), health(100) {}
void Card::set_attack(const std::string &name,
const std::string &level, const int damage) {
assert(level == "Base" || level == "Ultra");
if (level == "Base") {
base.set_name(name);
base.set_strength(damage);
}
if (level == "Ultra") {
ultra.set_name(name);
ultra.set_strength(damage);
}
}
string Card::get_element() const {
return element;
}
string Card::get_form() const {
return form;
}
bool Card::is_origin_form() const{
if (element == PYRO && form == PHOENIX) {
return true;
}
else if (element == AQUA && form == LEVIATHAN) {
return true;
}
else if (element == EARTH && form == BEHEMOTH) {
return true;
}
else if (element == AERO && form == GRIFFIN) {
return true;
}
else if (element == SPECTRAL && form == DJINN) {
return true;
}
else if (element == GLEAM && form == DJINN) {
return true;
}
else {
return false;
}
}
void Card::reduce_health(int damage) {
assert(damage == 30 || damage == 70 || damage == 0);
health -= damage;
}
int Card::get_health() {
return health;
}
void Card::reset() {
health = 100;
}
Attack Card::get_attack(string choice) {
Attack empty;
empty.set_name("Missed");
empty.set_strength(0);
if (choice == "base") {
cout << *this << " used " << base << endl;
return base;
}
else if (choice == "ultra") {
cout << *this << " used " << ultra << endl;
return ultra;
}
else {
cout << *this << " " << empty << endl;
return empty;
}
}
bool Card::alive() const {
if (health > 0) {
return true;
}
else {
return false;
}
}
Attack Card::get_base() {
return base;
}
Attack Card::get_ultra() {
return ultra;
}
std::ostream & operator<<(std::ostream &os, const Card &card) {
os << card.get_element() << " " << card.get_form();
return os;
}
bool operator==(const Card &lhs, const Card &rhs) {
if (lhs.get_form() == rhs.get_form() &&
lhs.get_element() == rhs.get_element()) {
return true;
}
else {
return false;
}
}
bool card_better(const Card &a, const Card &b,
const std::string &aura_in, int round) {
assert(round == 1 || round == 2);
if (round == 1) {
if (a.is_origin_form() && a.get_element() == aura_in) {
return true;
}
else if (a.is_origin_form() && a.get_element() == aura_in) {
return false;
}
else if (a.is_origin_form()) {
if (b.is_origin_form()) {
return false;
}
else {
return true;
}
}
else if (b.is_origin_form()) {
if (a.is_origin_form()) {
return false;
}
else {
return false;
}
}
else if (a.get_element() == aura_in) {
if (b.get_element() == aura_in) {
return false;
}
else {
return true;
}
}
else if (b.get_element() == aura_in) {
if (a.get_element() == aura_in) {
return false;
}
else {
return false;
}
}
else {
return false;
}
}
if (round == 2) {
if (a.is_origin_form()) {
if (b.is_origin_form()) {
return false;
}
else {
return true;
}
}
else if (b.is_origin_form()) {
if (a.is_origin_form()) {
return false;
}
else {
return false;
}
}
else if (a.get_element() == aura_in) {
if (b.get_element() == aura_in) {
return false;
}
else {
return true;
}
}
else if (b.get_element() == aura_in) {
if (a.get_element() == aura_in) {
return false;
}
else {
return false;
}
}
else {
return false;
}
}
return false;
}