-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBoard.cpp
367 lines (340 loc) · 13.8 KB
/
Board.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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
//Board.cpp
// CSCI 1300 Spring 2022
// Author: Matthew Cerza
// Recitation: 202 – Alex Ray
// Project 3
#include <iostream>
#include "Board.h"
using namespace std;
//Creates a new board object and sets all slots to be empty.
Board::Board(){
scale = 0;
for (int i=0; i<2; i++){
for (int j=0; j<4; j++){
Card blank;
board[i][j] = blank;
}
}
}
//Recursive Print Board function.
//Prints out the board for the current combat scenario. A board is defined as a 2x4 area of spaces, each of which can either be empty or contain a card
//The top row contain's the computer's creatures, and the bottom the player's.
//A "scale" containing the current score of the combat scenario is also printed on the left.
//The combat scenario ends when the score reaches 5 (player wins) or -5 (player loses)
int Board::printBoard(int recur){
if (recur==0){
cout << " Inscryption-CMD" << endl;
return printBoard(1);
} else if (recur==1){
cout << " Scale ---------------------------------------------" << endl;
return printBoard(2);
} else if (recur==2){
cout << " | " << board[0][0].getAttack() << " " << board[0][0].getHealth() << " | " << board[0][1].getAttack() << " " << board[0][1].getHealth() << " | " << board[0][2].getAttack() << " " << board[0][2].getHealth() << " | " << board[0][3].getAttack() << " " << board[0][3].getHealth() << " | " << endl;
return printBoard(3);
} else if (recur==3){
cout << " ";
for (int i=0; i<4; i++){
string s = board[0][i].getSigil();
string s2;
if (s.length()>9){
s2 = s.substr(0,9);
} else {
s2 = s;
}
if (s2.length() == 0){
cout << "| ";
} else {
cout << "|" << s2;
for (int j=s2.length(); j<10; j++){
cout << " ";
}
}
}
cout << "|" << endl;
return printBoard(4);
} else if (recur==4){
cout << " ";
for (int i=0; i<4; i++){
string s = board[0][i].getName();
string s2;
if (s.length()>9){
s2 = s.substr(0,9);
} else {
s2 = s;
}
if (s2.length() == 0){
cout << "| ";
} else {
cout << "|" << s2;
for (int j=s2.length(); j<10; j++){
cout << " ";
}
}
}
cout << "|" << endl;
return printBoard(5);
} else if (recur==5){
if(getScale()>=0){
cout << " +" << getScale() << " ---------------------------------------------" << endl;
} else {
cout << " " << getScale() << " ---------------------------------------------" << endl;
}
return printBoard(6);
} else if (recur==6){
cout << " | " << board[1][0].getAttack() << " " << board[1][0].getHealth() << " | " << board[1][1].getAttack() << " " << board[1][1].getHealth() << " | " << board[1][2].getAttack() << " " << board[1][2].getHealth() << " | " << board[1][3].getAttack() << " " << board[1][3].getHealth() << " | " << endl;
return printBoard(7);
} else if (recur==7){
cout << " ";
for (int i=0; i<4; i++){
string s = board[1][i].getSigil();
string s2;
if (s.length()>9){
s2 = s.substr(0,9);
} else {
s2 = s;
}
if (s2.length() == 0){
cout << "| ";
} else {
cout << "|" << s2;
for (int j=s2.length(); j<10; j++){
cout << " ";
}
}
}
cout << "|" << endl;
return printBoard(8);
} else if (recur==8){
cout << " ";
for (int i=0; i<4; i++){
string s = board[1][i].getName();
string s2;
if (s.length()>9){
s2 = s.substr(0,9);
} else {
s2 = s;
}
if (s2.length() == 0){
cout << "| ";
} else {
cout << "|" << s2;
for (int j=s2.length(); j<10; j++){
cout << " ";
}
}
}
cout << "|" << endl;
return printBoard(9);
} else if (recur==9){
cout << " ---------------------------------------------" << endl;
return printBoard(10);
} else if (recur==10){
return 1;
} else {
//Something is very wrong if this gets triggered.
return 0;
}
}
//Adds a card in the given space to the current board
void Board::addCard(int row, int col, Card toAdd){
board[row][col] = toAdd;
}
//Removes a card in the given space
void Board::removeCard(int row, int col){
Card blank;
board[row][col] = blank;
}
//Gets the "score" of the current board.
int Board::getScale(){
return scale;
}
//Gets the card at a given row and column
Card Board::getCardAt(int row, int col){
return board[row][col];
}
//Give damage to the scale, increasing the player's current score.
int Board::giveDamage(int dmg){
scale+=dmg;
return scale;
}
//Take damage to the scale, decreasing the player's score
int Board::takeDamage(int dmg){
scale-=dmg;
return scale;
}
//Set the card at a given row and column
void Board::setCardAt(int row, int col, Card givenCard){
board[row][col] = givenCard;
}
void Board::cardTakesDamage(int row, int col, int dmg){
board[row][col].setHealth(board[row][col].getHealth() - dmg);
}
void Board::addEnemyCards(int difficulty){
int cardsPlayed = 0;
bool twoCardsPlayed = false;
double random = rand();
random = rand();
random = random/RAND_MAX;
if ((random>=0.97-(difficulty/10.0))&&board[0][0].getHealth()==0){
Card grizzly("Grizzly", 6,4,"","The massive grizzly. It's mere presense makes other creatures shudder in fear.",3,false);
board[0][0] = grizzly;
cardsPlayed++;
//Hardest
} else if ((random>=0.85-(difficulty/10.0))&&board[0][0].getHealth()==0){
Card Wolf("Wolf", 3,2,"","The tenacious wolf. It's presense inspires confidince on creatures near it.", 2, false);
board[0][0] = Wolf;
cardsPlayed++;
//Hard
} else if ((random>=0.6-(difficulty/10.0)&&board[0][0].getHealth()==0)){
Card Mouse("Mouse",1,1,"","A tiny field mouse. While seemingly weak, it's agility makes it a possible threat.",1,false);
board[0][0] = Mouse;
cardsPlayed++;
//Easy
}
double randomTwo = rand();
randomTwo = rand();
randomTwo = randomTwo/RAND_MAX;
if ((randomTwo>=0.97-(difficulty/10.0))&&board[0][1].getHealth()==0){
Card grizzly("Grizzly", 6,4,"","The massive grizzly. It's mere presense makes other creatures shudder in fear.",3,false);
board[0][1] = grizzly;
cardsPlayed++;
//Hardest
} else if ((randomTwo>=0.85-(difficulty/10.0)&&board[0][1].getHealth()==0)){
Card Wolf("Wolf", 3,2,"","The tenacious wolf. It's presense inspires confidince on creatures near it.", 2, false);
board[0][1] = Wolf;
cardsPlayed++;
//Hard
} else if ((randomTwo >=0.6-(difficulty/10.0)&&board[0][1].getHealth()==0)){
Card Mouse("Mouse",1,1,"","A tiny field mouse. While seemingly weak, it's agility makes it a possible threat.",1,false);
board[0][1] = Mouse;
cardsPlayed++;
//Easy
}
double randomThree = rand();
randomThree = rand();
randomThree = randomThree/RAND_MAX;
if (cardsPlayed<2){
if ((randomThree>=0.97-(difficulty/10.0))&&board[0][2].getHealth()==0){
//Hardest
Card grizzly("Grizzly", 6,4,"","The massive grizzly. It's mere presense makes other creatures shudder in fear.",3,false);
board[0][2] = grizzly;
cardsPlayed++;
} else if ((randomThree>=0.85-(difficulty/10.0)&&board[0][2].getHealth()==0)){
Card Wolf("Wolf", 3,2,"","The tenacious wolf. It's presense inspires confidince on creatures near it.", 2, false);
board[0][2] = Wolf;
cardsPlayed++;
//Hard
} else if ((randomThree >=0.6-(difficulty/10.0)&&board[0][2].getHealth()==0)){
Card Mouse("Mouse",1,1,"","A tiny field mouse. While seemingly weak, it's agility makes it a possible threat.",1,false);
board[0][2] = Mouse;
cardsPlayed++;
//Easy
}
}
double randomFour = rand();
randomFour = rand();
randomFour = randomFour/RAND_MAX;
if (cardsPlayed<2){
if ((randomFour>=0.97-(difficulty/10.0))&&board[0][3].getHealth()==0){
//Hardest
Card grizzly("Grizzly", 6,4,"","The massive grizzly. It's mere presense makes other creatures shudder in fear.",3,false);
board[0][3] = grizzly;
cardsPlayed++;
} else if ((randomFour>=0.85-(difficulty/10.0)&&board[0][3].getHealth()==0)){
Card Wolf("Wolf", 3,2,"","The tenacious wolf. It's presense inspires confidince on creatures near it.", 2, false);
board[0][3] = Wolf;
//Hard
cardsPlayed++;
} else if ((randomFour >=0.6-(difficulty/10.0)&&board[0][3].getHealth()==0)){
Card Mouse("Mouse",1,1,"","A tiny field mouse. While seemingly weak, it's agility makes it a possible threat.",1,false);
board[0][3] = Mouse;
//Easy
cardsPlayed++;
}
}
cout << "Random: " << random << " Random2: " << randomTwo << " Random3: " << randomThree << " Random4: " << randomFour << endl;
}
void Board::startEnemyCards(int difficulty){
int cardsPlayed = 0;
double random = rand();
random = rand();
random = random/RAND_MAX;
if ((random>=0.97-(difficulty/10.0))&&board[0][0].getHealth()==0){
Card grizzly("Grizzly", 6,4,"","The massive grizzly. It's mere presense makes other creatures shudder in fear.",3,false);
board[0][0] = grizzly;
cardsPlayed++;
//Hardest
} else if ((random>=0.85-(difficulty/10.0))&&board[0][0].getHealth()==0){
Card Wolf("Wolf", 3,2,"","The tenacious wolf. It's presense inspires confidince on creatures near it.", 2, false);
board[0][0] = Wolf;
cardsPlayed++;
//Hard
} else if ((random >=0.6-(difficulty/10.0))&&board[0][0].getHealth()==0){
Card Mouse("Mouse",1,1,"","A tiny field mouse. While seemingly weak, it's agility makes it a possible threat.",1,false);
board[0][0] = Mouse;
cardsPlayed++;
//Easy
}
double randomTwo = rand();
randomTwo = rand();
randomTwo = randomTwo/RAND_MAX;
if ((randomTwo>=0.97-(difficulty/10.0))&&board[0][1].getHealth()==0){
Card grizzly("Grizzly", 6,4,"","The massive grizzly. It's mere presense makes other creatures shudder in fear.",3,false);
board[0][1] = grizzly;
cardsPlayed++;
//Hardest
} else if ((randomTwo>=0.85-(difficulty/10.0)&&board[0][1].getHealth()==0)){
Card Wolf("Wolf", 3,2,"","The tenacious wolf. It's presense inspires confidince on creatures near it.", 2, false);
board[0][1] = Wolf;
cardsPlayed++;
//Hard
} else if ((randomTwo >=0.6-(difficulty/10.0)&&board[0][1].getHealth()==0)){
Card Elk("Elk",4,2,"Sprinter","The flightly Elk. It attempts to move to the right after it's turn",2,false);
board[0][1] = Elk;
cardsPlayed++;
//Easy
}
double randomThree = rand();
randomThree = rand();
randomThree = randomThree/RAND_MAX;
if (cardsPlayed<2){
if ((randomThree>=0.97-(difficulty/10.0))&&board[0][2].getHealth()==0){
//Hardest
Card grizzly("Grizzly", 6,4,"","The massive grizzly. It's mere presense makes other creatures shudder in fear.",3,false);
board[0][2] = grizzly;
cardsPlayed++;
} else if ((randomThree>=0.85-(difficulty/10.0)&&board[0][2].getHealth()==0)){
Card Wolf("Wolf", 3,2,"","The tenacious wolf. It's presense inspires confidince on creatures near it.", 2, false);
board[0][2] = Wolf;
cardsPlayed++;
//Hard
} else if ((randomThree >=0.6-(difficulty/10.0)&&board[0][2].getHealth()==0)){
Card Elk("Elk",4,2,"Sprinter","The flightly Elk. It attempts to move to the right after it's turn",2,false);
board[0][2] = Elk;
cardsPlayed++;
//Easy
}
}
double randomFour = rand();
randomFour = rand();
randomFour = randomFour/RAND_MAX;
if (cardsPlayed<2){
if ((randomFour>=0.97-(difficulty/10.0))&&board[0][3].getHealth()==0){
//Hardest
Card grizzly("Grizzly", 6,4,"","The massive grizzly. It's mere presense makes other creatures shudder in fear.",3,false);
board[0][3] = grizzly;
cardsPlayed++;
} else if ((randomFour>=0.85-(difficulty/10.0)&&board[0][3].getHealth()==0)){
Card Wolf("Wolf", 3,2,"","The tenacious wolf. It's presense inspires confidince on creatures near it.", 2, false);
board[0][3] = Wolf;
cardsPlayed++;
//Hard
} else if (randomFour>=(0.6-(difficulty/10.0))&&board[0][3].getHealth()==0){
Card Elk("Elk",4,2,"Sprinter","The flightly Elk. It attempts to move to the right after it's turn",2,false);
board[0][3] = Elk;
cardsPlayed++;
//Easy
}
}
cout << "Random: " << random << " Random2: " << randomTwo << " Random3: " << randomThree << " Random4: " << randomFour << " CardsPlayed: " <<cardsPlayed << endl;
}