-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
2859 lines (2510 loc) · 114 KB
/
main.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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <iostream>
#include <vector>
#include <memory>
#include <cstdlib>
#include <ctime>
#include <stdlib.h>
//======================================================================================================================
/**
* @class Mana
* @brief Represents the mana pool of a player in a card game.
*
* The Mana class keeps track of the different types of mana (white, red, green, blue, black) that a player has.
* It provides methods to reset the mana each turn, print the mana information, get user input for mana selection,
* check if the mana is enough to play a card, and deduct mana when playing a card.
*
* The class also includes a map that stores the mana costs and requirements for each card in the game.
* It provides methods to check if the player has enough mana for a card and to get the count of a specific type of mana.
*
* The Mana class can be inherited to add additional functionality or mana types.
*/
class Mana
{
protected:
int whiteMana;
int redMana;
int greenMana;
int blueMana;
int blackMana;
int colorlessManaSum;
std::string cardName;
public:
Mana() : whiteMana(1), redMana(1), greenMana(1), blueMana(1), blackMana(1), colorlessManaSum(whiteMana + redMana + greenMana + blueMana + blackMana) {}
//----------------------------------------------------------------------------------------------------------------------
/**
* @brief Resets the mana value to its initial state.
*/
void resetMana()
{
whiteMana = 0;
redMana = 0;
greenMana = 0;
blueMana = 0;
blackMana = 0;
}
//----------------------------------------------------------------------------------------------------------------------
/**
* @brief Prints the mana value.
*/
void printMana()
{
std::cout << "White mana: " << whiteMana << " / "
<< "Green mana: " << greenMana << " / "
<< "Blue mana: " << blueMana << " / "
<< "Red mana: " << redMana << " / "
<< "Black mana: " << blackMana << std::endl;
}
//----------------------------------------------------------------------------------------------------------------------
/**
* @brief Retrieves the mana value.
*
* This function is used to get the mana value for a player in a card game.
*
* @return The mana value.
*/
void getMana()
{
colorlessManaSum = whiteMana + redMana + greenMana + blueMana + blackMana;
std::string temp;
std::cout << "Choose whichever color of mana you want to use " << std::endl;
std::cout << "R for red / W for white / G for green / L for blue / B for black " << std::endl;
std::cin >> temp;
if (temp == "R" && redMana > 0)
{
redMana--;
}
else if (temp == "R" && redMana <= 0)
{
std::cout << "You dont have enough mana. " << std::endl;
getMana();
}
else if (temp == "W" && whiteMana > 0)
{
whiteMana--;
}
else if (temp == "W" && whiteMana <= 0)
{
std::cout << "You dont have enough mana. " << std::endl;
getMana();
}
else if (temp == "G" && greenMana > 0)
{
greenMana--;
}
else if (temp == "G" && greenMana <= 0)
{
std::cout << "You dont have enough mana. " << std::endl;
getMana();
}
else if (temp == "L" && blueMana > 0)
{
blueMana--;
}
else if (temp == "L" && blueMana <= 0)
{
std::cout << "You dont have enough mana. " << std::endl;
getMana();
}
else if (temp == "B" && blackMana > 0)
{
blackMana--;
}
else if (temp == "B" && blackMana <= 0)
{
std::cout << "You dont have enough mana. " << std::endl;
getMana();
}
}
//----------------------------------------------------------------------------------------------------------------------
/**
* Calculates the cost of a card based on its name.
*
* @param cardName The name of the card.
*/
void cost(const std::string &cardName)
{
const int colorlessManaSum = whiteMana + redMana + greenMana + blueMana + blackMana;
// Map to store mana costs for each card
std::unordered_map<std::string, std::vector<std::pair<std::string, int>>> manaCosts = {
{"Soldier", {{"white", 1}}},
{"ArmoredPegasus", {{"white", 1}, {"colorless", 1}}},
{"WhiteKnight", {{"white", 2}}},
{"AngryBear", {{"green", 1}, {"colorless", 2}}},
{"Guard", {{"white", 2}, {"colorless", 2}}},
// ... (continue for other cards)
};
auto it = manaCosts.find(cardName);
if (it != manaCosts.end())
{
// Check if the player has enough mana for the card
for (const auto &cost : it->second)
{
if (cost.first == "colorless" && cost.second <= colorlessManaSum)
{
continue;
}
else if (cost.second > getManaCount(cost.first))
{
std::cout << "Not enough mana for " << cardName << ". " << std::endl;
return;
}
}
// Deduct the mana cost
for (const auto &cost : it->second)
{
if (cost.first != "colorless")
{
deductMana(cost.first);
}
else
{
for (int i = 0; i < cost.second; ++i)
{
deductMana(cost.first);
}
}
}
}
else
{
std::cout << "Card " << cardName << " not found." << std::endl;
}
}
//----------------------------------------------------------------------------------------------------------------------
/**
* Deducts mana of the specified type.
*
* @param manaType The type of mana to deduct.
*/
void deductMana(const std::string &manaType)
{
if (manaType == "white")
{
whiteMana--;
}
else if (manaType == "red")
{
redMana--;
}
else if (manaType == "green")
{
greenMana--;
}
else if (manaType == "blue")
{
blueMana--;
}
else if (manaType == "black")
{
blackMana--;
}
}
//----------------------------------------------------------------------------------------------------------------------
/**
* Checks if the mana is enough for a given card.
*
* @param cardName The name of the card.
* @return True if the mana is enough, false otherwise.
*/
bool isManaEnough(const std::string &cardName)
{
const int colorlessManaSum = whiteMana + redMana + greenMana + blueMana + blackMana;
// Map to store mana requirements for each card
std::unordered_map<std::string, std::vector<std::pair<std::string, int>>> manaRequirements = {
{"Soldier", {{"white", 1}}},
{"ArmoredPegasus", {{"white", 1}, {"colorless", 1}}},
{"WhiteKnight", {{"white", 2}}},
{"AngryBear", {{"green", 1}, {"colorless", 2}}},
{"Guard", {{"white", 2}, {"colorless", 2}}},
{"Werewolf", {{"white", 1}, {"green", 1}, {"colorless", 2}}},
{"Skeleton", {{"black", 1}}},
{"Ghost", {{"black", 1}, {"colorless", 1}}},
{"BlackKnight", {{"black", 2}}},
{"OrcManiac", {{"red", 1}, {"colorless", 2}}},
{"Hobgoblin", {{"red", 1}, {"black", 1}, {"colorless", 1}}},
{"Vampire", {{"black", 1}, {"colorless", 3}}},
// Sorcery Cards
{"Disenchant", {{"white", 1}, {"colorless", 1}}},
{"LightningBolt", {{"green", 1}, {"colorless", 1}}},
{"Flood", {{"white", 1}, {"green", 1}, {"colorless", 1}}},
{"Reanimate", {{"black", 1}}},
{"Plague", {{"black", 1}, {"colorless", 2}}},
{"Terror", {{"black", 1}, {"colorless", 1}}},
// Enchantment Cards
{"Rage", {{"green", 1}}},
{"HolyWar", {{"white", 1}, {"colorless", 1}}},
{"HolyLight", {{"white", 1}, {"colorless", 1}}},
{"UnholyWar", {{"black", 1}, {"colorless", 1}}},
{"Restrain", {{"red", 1}, {"colorless", 2}}},
{"Slow", {{"black", 1}}},
// Basic Lands
{"Plains", {{"colorless", 1}}},
{"Island", {{"colorless", 1}}},
{"Mountain", {{"colorless", 1}}},
{"Swamp", {{"colorless", 1}}},
{"Forest", {{"colorless", 1}}}};
// Check if the card exists in the map
auto it = manaRequirements.find(cardName);
if (it != manaRequirements.end())
{
// Check if the player has enough mana for the card
for (const auto &requirement : it->second)
{
if (requirement.first == "colorless" && requirement.second <= colorlessManaSum)
{
continue;
}
else if (requirement.second > getManaCount(requirement.first))
{
return false;
}
}
return true;
}
return false; // Card not found in the map
}
//----------------------------------------------------------------------------------------------------------------------
/**
* @brief Get the count of mana of a specific type.
*
* @param manaType The type of mana to count.
* @return The count of mana of the specified type.
*/
int getManaCount(const std::string &manaType)
{
if (manaType == "white")
{
return whiteMana;
}
else if (manaType == "red")
{
return redMana;
}
else if (manaType == "green")
{
return greenMana;
}
else if (manaType == "blue")
{
return blueMana;
}
else if (manaType == "black")
{
return blackMana;
}
else
{
return 0;
}
}
//----------------------------------------------------------------------------------------------------------------------
/**
* Increases the mana with tap for a given card.
*
* @param c The card for which the mana needs to be increased.
*/
virtual void increaseManaWithTap(std::string c)
{
cardName = c;
if (c == "Forest")
{
greenMana++;
}
else if (c == "Island")
{
blueMana++;
}
else if (c == "Mountain")
{
redMana++;
}
else if (c == "Plains")
{
whiteMana++;
}
else if (c == "Swamp")
{
blackMana++;
}
}
}; // Mana class
//======================================================================================================================
/**
* @class Card
* @brief Represents a card in a card game.
*
* The Card class provides functionality to create and manipulate cards in a card game.
* It contains properties such as card name, type, and color, as well as various methods
* for printing card information, modifying card stats, and performing card actions.
* This class serves as a base class for specific types of cards in the game.
*/
class Card
{
protected:
std::string cardName, cardType, cardColor;
public:
Card() {}
Card(std::string cN, std::string tP, std::string c) : cardName(cN), cardType(tP), cardColor(c) {}
virtual void printCardName() { std::cout << cardName; }
void printCardtype() { std::cout << cardType; }
void printCardColor() { std::cout << cardColor; }
std::string getCardName() { return cardName; }
std::string getCardtype() { return cardType; }
std::string getCardColor() { return cardColor; }
virtual void BoostStats(){};
virtual void DecreaseStats(){};
virtual void BoostAttack(){};
virtual void deal1Dmg(){};
virtual void deal2Dmg(){};
virtual void setUntapped(){};
virtual void setTapped(std::unique_ptr<Mana> &mana){};
virtual void setFirstStrike(){};
virtual void setTrample(){};
virtual void removeTrample(){};
virtual void removeFirstStrike(){};
virtual bool getFirstStrike() { return false; };
virtual bool getTrample() { return false; };
virtual void play(std::unique_ptr<Mana> &mana)
{
std::cout << "Card play function ";
mana->cost(cardName);
}
virtual bool isManaE(std::unique_ptr<Mana> &mana) { return mana->isManaEnough(cardName); }
virtual void goBaseHp(){};
virtual bool hasTappedInfo() { return false; }
virtual int getHp() { return 0; }
virtual int getAttackPower() { return 0; }
virtual void sustainDamage(int dmg) {}
virtual bool checkDead() { return false; }
virtual void trampleBase() {}
virtual void firstStrikeBase() {}
virtual void reverseHolyWar() {}
virtual void reverseHolylight() {}
virtual void reverseUnholyWar() {}
}; // Card class
//======================================================================================================================
/**
* @brief The LandCard class represents a land card in a card game.
*
* It inherits from the Card class and adds functionality specific to land cards.
*/
class LandCard : public Card
{
protected:
bool hasTapped;
public:
/**
* @brief Default constructor for LandCard.
*/
LandCard() : Card(), hasTapped(0) {}
/**
* @brief Constructor for LandCard with specified parameters.
*
* @param cN The name of the card.
* @param t The type of the card.
* @param hT A boolean indicating whether the card has been tapped.
*/
LandCard(std::string cN, std::string t, bool hT) : Card(cN, t, " "), hasTapped(hT) {}
/**
* @brief Plays the land card.
*
* @param mana A reference to a unique_ptr of Mana.
*/
void play(std::unique_ptr<Mana> &mana)
{
std::cout << "land card play function ";
mana->cost(cardName);
}
/**
* @brief Prints the name of the card.
*/
void printCardName() { std::cout << cardName; }
/**
* @brief Sets the land card as untapped.
*/
void setUntapped() { hasTapped = false; }
/**
* @brief Sets the land card as tapped and increases mana with tap.
*
* @param mana A reference to a unique_ptr of Mana.
*/
void setTapped(std::unique_ptr<Mana> &mana)
{
mana->increaseManaWithTap(cardName);
hasTapped = true;
}
/**
* @brief Checks if the land card has been tapped.
*
* @return true if the land card has been tapped, false otherwise.
*/
bool hasTappedInfo() { return hasTapped; }
/**
* @brief Checks if the land card is a mana card.
*
* @return true if the land card is a mana card, false otherwise.
*/
bool isManaE() { return true; }
}; // LandCard class
//======================================================================================================================
/**
* @brief The CreatureCard class represents a card that is a creature in a card game.
*
* It inherits from the Card class and adds additional properties and methods specific to creature cards.
*/
class CreatureCard : public Card
{
protected:
std::string manaCost;
int attackPower;
int baseHP;
int hp = baseHP;
bool baseFirstStrike;
bool baseTrample;
bool hasTapped;
bool firstStrike = baseFirstStrike;
bool trample = baseTrample;
public:
CreatureCard() : Card(), attackPower(0), baseHP(0), manaCost(" "), baseFirstStrike(0), baseTrample(0)
{
}
CreatureCard(std::string cardName, std::string type, std::string color, int attack, int hp, std::string cost, bool firstStrike, bool trample) : Card(cardName, type, color), attackPower(attack), baseHP(hp), manaCost(cost), baseFirstStrike(firstStrike), baseTrample(trample)
{
}
void play(std::unique_ptr<Mana> &mana) { mana->cost(cardName); }
void printCardName() { std::cout << cardName; }
void BoostStats()
{
attackPower++;
hp++;
}
void DecreaseStats()
{
attackPower--;
hp--;
}
void BoostAttack() { attackPower += 2; }
void reverseHolyWar()
{
attackPower--;
hp--;
}
void reverseHolylight()
{
attackPower++;
hp++;
}
void reverseUnholyWar()
{
if (attackPower == 0 || attackPower < 0)
{
}
else if (attackPower == 1)
{
attackPower--;
}
else
{
attackPower -= 2;
}
}
void deal1Dmg() { hp--; }
void deal2Dmg() { hp -= 2; }
int dealAttack() { return attackPower; }
void setUntapped() { hasTapped = false; }
void setTapped() { hasTapped = true; }
void setFirstStrike() { firstStrike = true; }
void setTrample() { trample = true; }
void removeTrample() { trample = false; }
void removeFirstStrike() { firstStrike = false; }
bool getFirstStrike() { return firstStrike; }
bool getTrample() { return trample; }
void trampleBase() { trample = baseTrample; }
void firstStrikeBase() { firstStrike = baseFirstStrike; }
void goBaseHp() { hp = baseHP; }
bool hasTappedInfo() { return hasTapped; }
bool isManaE(std::unique_ptr<Mana> &mana) { return mana->isManaEnough(cardName); }
int getHp() { return hp; }
int getAttackPower() { return attackPower; }
void sustainDamage(int dmg) { hp -= dmg; }
bool checkDead()
{
if (hp < 1)
{
return true;
}
else
{
return false;
}
}
}; // CreatureCard class
//======================================================================================================================
/**
* @brief The SorceryCard class represents a sorcery card in a card game.
*
* It inherits from the Card class and adds additional properties and methods specific to sorcery cards.
*/
class SorceryCard : public Card
{
protected:
std::string effect2, manaCost2;
public:
/**
* @brief Default constructor for SorceryCard.
*/
SorceryCard() : Card(), manaCost2(" "), effect2(" ") {}
/**
* @brief Constructor for SorceryCard.
*
* @param cN2 The name of the sorcery card.
* @param cC2 The color of the sorcery card.
* @param mC2 The mana cost of the sorcery card.
* @param ef2 The effect of the sorcery card.
*/
SorceryCard(std::string cN2, std::string cC2, std::string mC2, std::string ef2) : Card(cN2, "SorceryCard", cC2), manaCost2(mC2), effect2(ef2) {}
/**
* @brief Prints the name of the sorcery card.
*/
void printCardName() { std::cout << cardName; }
/**
* @brief Plays the sorcery card using the provided mana.
*
* @param mana A reference to the mana object.
*/
void play(std::unique_ptr<Mana> &mana) { mana->cost(cardName); }
/**
* @brief Checks if the mana is enough to play the sorcery card.
*
* @param mana A reference to the mana object.
* @return True if the mana is enough, false otherwise.
*/
bool isManaE(std::unique_ptr<Mana> &mana) { return mana->isManaEnough(cardName); }
}; // SorceryCard class
//======================================================================================================================
/**
* @class EnhancementCard
* @brief Represents an enhancement card in a card game.
*
* This class inherits from the Card class and adds additional properties and methods specific to enhancement cards.
*/
class EnhancementCard : public Card
{
protected:
std::string effect2, manaCost2;
public:
EnhancementCard() : Card(), manaCost2(" "), effect2(" ") {}
EnhancementCard(std::string cN2, std::string cC2, std::string mC2, std::string ef2) : Card(cN2, "EnhancementCard", cC2), manaCost2(mC2), effect2(ef2) {}
void printCardName() { std::cout << cardName; }
void play(std::unique_ptr<Mana> &mana) { mana->cost(cardName); }
bool isManaE(std::unique_ptr<Mana> &mana) { return mana->isManaEnough(cardName); }
}; // EnhancementCard class
//======================================================================================================================
/**
* @class Player
* @brief Represents a player in the card game.
*
* The Player class contains information about the player's health points (hp) and their card deck.
* It provides methods for dealing damage, randomizing the deck, and getting the player's current hp.
*/
class Player
{
protected:
int hp = 15;
std::vector<std::shared_ptr<Card>> library;
std::vector<std::shared_ptr<Card>> libraryx;
std::vector<std::shared_ptr<Card>> hand;
std::vector<std::shared_ptr<Card>> inPlay;
std::vector<std::shared_ptr<Card>> discard;
public:
Player() {}
Player(std::vector<std::shared_ptr<Card>> &lib, std::vector<std::shared_ptr<Card>> &hnd, std::vector<std::shared_ptr<Card>> &iP, std::vector<std::shared_ptr<Card>> &dc) : library(lib), hand(hnd), inPlay(iP), discard(dc) { libaryRandomizeAndHand7Initialy(lib, hnd); }
//----------------------------------------------------------------------------------------------------------------------
void deal2Dmg() { hp -= 2; }
//----------------------------------------------------------------------------------------------------------------------
/**
* Randomizes the cards in the library and deals 7 cards to the hand.
*
* @param lib The library of cards.
* @param hnd The hand of cards.
*/
void libaryRandomizeAndHand7Initialy(std::vector<std::shared_ptr<Card>> &lib, std::vector<std::shared_ptr<Card>> &hnd)
{
int a[26];
for (int i = 0; i < 26; i++)
{
bool isUsedBefore = false;
a[i] = (rand() % library.size());
for (int j = 0; j < i; j++)
{
if (a[i] == a[j])
{
isUsedBefore = true;
}
}
if (!isUsedBefore)
{
libraryx.emplace_back(library[a[i]]);
}
else
{
i--;
}
}
lib = library = libraryx;
for (int i = 0; i < 5; i++)
{
hnd.emplace_back(lib[lib.size() - 1]);
lib.pop_back();
}
}
//----------------------------------------------------------------------------------------------------------------------
void susDamage(int dmg) { hp -= dmg; }
//----------------------------------------------------------------------------------------------------------------------
int getHp() { return hp; }
}; // Player class
//======================================================================================================================
/**
* @brief Represents an effect in the card game.
*
* This class is responsible for defining the behavior of an effect in the card game.
* It serves as a base class for specific types of effects.
*/
class Effect
{
}; // Effect class
//======================================================================================================================
/**
* @class DestroyCardEffect
* @brief Represents an effect that destroys cards in a card game.
*
* The DestroyCardEffect class is a subclass of the Effect class and provides functionality
* to destroy specific types of cards in the game. It allows the player to choose a card to destroy
* from a given set of cards and performs the necessary actions based on the type of card destroyed.
*
* The DestroyCardEffect class contains a single public method, destroyCardEffectFunc, which takes
* in the player's cards, the discard pile, and the type of card to destroy as parameters. It then
* performs the necessary actions to destroy the chosen card and updates the game state accordingly.
*/
class DestroyCardEffect : public Effect
{
public:
/**
* @brief Destroys a specific type of card in the game.
*
* This method allows the player to choose a card of a specific type (e.g., EnhancementCard,
* LandCard, CreatureCard) to destroy from the opponent's in-play cards. It prompts the player
* to choose the card to destroy and performs the necessary actions based on the type of card destroyed.
*
* @param ip The opponent's in-play cards.
* @param discard The discard pile.
* @param s The type of card to destroy.
*/
void destroyCardEffectFunc(std::vector<std::shared_ptr<Card>> &ip, std::vector<std::shared_ptr<Card>> &discard, std::string s)
{
// Implementation code...
}
}; // DestroyCardEffect class
class DestroyCardEffect : public Effect
{
public:
void destroyCardEffectFunc(std::vector<std::shared_ptr<Card>> &ip, std::vector<std::shared_ptr<Card>> &discard, std::string s)
{
auto it = ip.begin();
bool isThereDestroyable = false;
if (s == "Disenchant")
{
for (it = ip.begin(); it != ip.end(); it++)
{
if ((*it)->getCardtype() == "EnhancementCard")
{
isThereDestroyable = true;
}
}
if (isThereDestroyable)
{
std::cout << "please choose which Enhancement Card you want to destroy" << std::endl;
int i = 0;
for (it = ip.begin(); it != ip.end(); it++)
{
if ((*it)->getCardtype() == "EnhancementCard")
{
std::cout << i << ")" << std::endl;
i++;
(*it)->printCardName();
}
}
std::cin >> i;
std::cout << "opponent's " << ip[i]->getCardName()
<< " enhancement card has been destroyed and because of it is an enhancement card its effects are reversed and canceled "
<< std::endl;
std::string namen;
namen = ip[i]->getCardName();
if (namen == "Rage")
{
for (it = ip.begin(); it != ip.end(); it++)
{
(*it)->trampleBase();
}
}
else if (namen == "HolyWar")
{
for (it = ip.begin(); it != ip.end(); it++)
{
(*it)->reverseHolyWar();
}
}
else if (namen == "HolyLight")
{
for (it = ip.begin(); it != ip.end(); it++)
{
(*it)->reverseHolylight();
}
}
else if (namen == "UnholyWar")
{
for (it = ip.begin(); it != ip.end(); it++)
{
(*it)->reverseUnholyWar();
}
}
else if (namen == "Restrain")
{
for (it = ip.begin(); it != ip.end(); it++)
{
if ((*it)->getCardColor() == "Green")
(*it)->trampleBase();
}
}
else if (namen == "Slow")
{
for (it = ip.begin(); it != ip.end(); it++)
{
(*it)->trampleBase();
}
}
discard.emplace_back(ip[i]);
ip.erase(ip.begin() + i);
isThereDestroyable = false;
}
else
{
std::cout
<< "there is no destroyable enhancement card in opponents in play cards you have wasted your card"
<< std::endl;
}
}
else if (s == "Flood")
{
for (it = ip.begin(); it != ip.end(); it++)
{
if ((*it)->getCardtype() == "LandCard")
{
isThereDestroyable = true;
}
}
if (isThereDestroyable)
{
std::cout << "please choose which Land Card you want to destroy" << std::endl;
int i = 0;
for (it = ip.begin(); it != ip.end(); it++)
{
if ((*it)->getCardtype() == "LandCard")
{
std::cout << i << ")" << std::endl;
i++;
(*it)->printCardName();
}
}
std::cin >> i;
std::cout << "opponent's " << ip[i]->getCardName() << " land card has been destroyed" << std::endl;
discard.emplace_back(ip[i]);
ip.erase(ip.begin() + i);
isThereDestroyable = false;
}
else
{
std::cout << "there is no destroyable land card in opponents in play cards you have wasted your card"
<< std::endl;
isThereDestroyable = false;
}
}
else if (s == "Terror")
{
for (it = ip.begin(); it != ip.end(); it++)
{
if ((*it)->getCardtype() == "CreatureCard")
{
isThereDestroyable = true;
}
}
if (isThereDestroyable)
{
std::cout << "please choose which Creature Card you want to destroy" << std::endl;
int i = 0;
for (it = ip.begin(); it != ip.end(); it++)
{
if ((*it)->getCardtype() == "CreatureCard")
{
std::cout << i << ")" << std::endl;
i++;
(*it)->printCardName();
}
}
std::cin >> i;
std::cout << "opponent's " << ip[i]->getCardName() << " creature card has been destroyed" << std::endl;
discard.emplace_back(ip[i]);
ip.erase(ip.begin() + i);
isThereDestroyable = false;
}
else
{
std::cout
<< "there is no destroyable creature card in opponents in play cards you have wasted your card"
<< std::endl;
}
}
}
}; // DestroyCardEffect class
//======================================================================================================================
// Effect card stats
class EffectForColorEffect : public Effect
{
public:
void effectThatColorMembers(std::vector<std::shared_ptr<Card>> &ip, std::string s)
{
auto it = ip.begin();
if (s == "HolyWar")
{
for (it = ip.begin(); it != ip.end(); it++)
{
if ((*it)->getCardColor() == "White")
{
(*it)->BoostStats();
}
}
std::cout << "all white creature cards in your side that in play gain +1/+1 " << std::endl;
}
else if (s == "HolyLight")
{
for (it = ip.begin(); it != ip.end(); it++)
{
if ((*it)->getCardColor() == "Black")
{
(*it)->DecreaseStats();
}
}
std::cout << "all black creature cards in your side that in play gain -1/-1 " << std::endl;
}
else if (s == "UnholyWar")
{
for (it = ip.begin(); it != ip.end(); it++)
{
if ((*it)->getCardColor() == "Black")
{
(*it)->BoostAttack();
}
}
std::cout << "all black creature cards in your side that in play gain +2/0 " << std::endl;
}
}
}; // EffectForColorEffect class