-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCards.h
179 lines (164 loc) · 5.92 KB
/
Cards.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
#pragma once
#include <iostream>
#include <string>
#include<vector>
#include "Orders.h"
//Forward declarations
class Hand;
class Deck;
//Base class for all cards
class Card {
public:
//Copy constructor
Card();
//Constructor taking in a string which sets the type, used by the others.
Card(std::string type);
//Copy constructor
Card(const Card& otherCard);
//Destructor, VIRTUAL DUE TO INHERITANCE STRUCTURE AND USE OF POINTERS/POLYMORPHISM https://www.geeksforgeeks.org/virtual-destructor/
virtual ~Card();
//assignment operator
virtual Card& operator = (const Card& rightSide);
//Clone function, crucial for polymorphic calls to the copy constructor.
virtual Card* clone() const;
//Get the type of the card as a string
std::string getType() const;
//Play the card and return an order.
virtual Order* play();
///<summary>play method, returns the appropriate order type, removes the card from the passed in hand and inserts it into the deck.</summary>
///<param name='Hand* hand'>Hand to remove card from</param>
///<param name='Deck* deck'>Deck to add card to</param>
///<returns>A pointer to a new Order of relevant type for that card</returns>
virtual Order* play(Hand* hand, Deck* deck);
//stream insertion operator overload for Card
friend std::ostream& operator<<(std::ostream& strm, const Card& card);
private:
//The card type
std::string* _type;
};
//The Bomb type of card
class BombCard : public Card {
public:
//Default constructor
BombCard();
//Copy constructor
BombCard(const BombCard& otherCard);
//Destructor, VIRTUAL DUE TO INHERITANCE STRUCTURE AND USE OF POINTERS/POLYMORPHISM https://www.geeksforgeeks.org/virtual-destructor/
virtual ~BombCard();
//assignment operator
virtual BombCard& operator = (const BombCard& rightSide);
//Play the card and return a Bomb order.
Bomb* play();
//Clone function, crucial for polymorphic calls to the copy constructor.
virtual BombCard* clone() const;
};
//The Blockade type of card
class BlockadeCard : public Card {
public:
//Default Constructor
BlockadeCard();
//Copy constructor
BlockadeCard(const BlockadeCard& otherCard);
//Destructor, VIRTUAL DUE TO INHERITANCE STRUCTURE AND USE OF POINTERS/POLYMORPHISM https://www.geeksforgeeks.org/virtual-destructor/
virtual ~BlockadeCard();
//assignment operator
virtual BlockadeCard& operator = (const BlockadeCard& rightSide);
//Play the card and return a Blockade order.
Blockade* play();
//Clone function, crucial for polymorphic calls to the copy constructor.
virtual BlockadeCard* clone() const;
};
//The Airlift type of card
class AirliftCard : public Card {
public:
//Default Constructor
AirliftCard();
//Copy constructor
AirliftCard(const AirliftCard& otherCard);
//Destructor, VIRTUAL DUE TO INHERITANCE STRUCTURE AND USE OF POINTERS/POLYMORPHISM https://www.geeksforgeeks.org/virtual-destructor/
virtual ~AirliftCard();
//assignment operator
virtual AirliftCard& operator = (const AirliftCard& rightSide);
//Play the card and return an Airlift order.
Airlift* play();
//Clone function, crucial for polymorphic calls to the copy constructor.
virtual AirliftCard* clone() const;
};
//The Diplomacy type of card
class DiplomacyCard : public Card {
public:
//Default constructor
DiplomacyCard();
//Copy constructor
DiplomacyCard(const DiplomacyCard& otherCard);
//Destructor, VIRTUAL DUE TO INHERITANCE STRUCTURE AND USE OF POINTERS/POLYMORPHISM https://www.geeksforgeeks.org/virtual-destructor/
virtual ~DiplomacyCard();
//assignment operator
virtual DiplomacyCard& operator = (const DiplomacyCard& rightSide);
//Play the card and return a Negotiate order.
Negotiate* play();
//Clone function, crucial for polymorphic calls to the copy constructor.
virtual DiplomacyCard *clone() const;
};
//The Deck class, allows user to randomly draw a card and add cards back to it
class Deck {
public:
//Default constructor
Deck();
//Set up the deck with a predefined list of cards
Deck(std::vector<Card*> listOfCards);
//Copy constructor
Deck(const Deck& otherDeck);
//Destructor
~Deck();
//assignment operator
Deck& operator = (const Deck& rightSide);
//Gets the list of cards in the deck
std::vector<Card*> getCards();
//Returns a reference to a random card and removes it from the deck.
Card* draw();
//Return a card to the deck, adding it to the _cards list.
void returnToDeck(Card* card);
//Return if the internal list of cards is empty. Wrapper method
bool isEmpty();
private:
//The list of cards
std::vector<Card*>* _cards;
//stream insertion operator overload for Deck
friend std::ostream& operator<<(std::ostream& strm, const Deck& deck);
};
//The Hand class, used by the Player to store cards. Contains methods for adding cards to it and the play and return card to deck method.
class Hand {
public:
//Default constructor
Hand();
//Copy constructor
Hand(const Hand& otherHand);
//Destructor
~Hand();
//assignment operator
Hand& operator = (const Hand& rightSide);
//add a card to your hand
void addCard(Card* card);
//gets all cards in the hand
std::vector<Card*> getCards();
//Clears hand
void clearHand();
//Return the size of the hand.
int size();
//Get a card at a specific index in the hand
Card* getCard(int index);
//Return the card pointer and remove it from _cards based on passed in index
void returnCardToDeck(int index, Deck* deck);
///<summary>Play a card and return it to the passed in deck. Returns an Order</summary>
///<param name='int index'>Index of card to play and remove</param>
///<param name='Deck* deck'>Deck to add card to</param>
///<returns>A pointer to a new Order of relevant type for that card</returns>
Order* playAndReturnToDeck(int index, Deck* deck);
//Find if a specific card exists in the Hand. Checks if that EXACT object is in the Hand and returns the index. Returns -1 if not.
int indexOfCard(Card* card);
private:
std::vector<Card*>* _cards;
//stream insertion operator overload for Hand
friend std::ostream& operator<<(std::ostream& strm, const Hand& hand);
};