-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrders.h
More file actions
254 lines (186 loc) · 8.25 KB
/
Copy pathOrders.h
File metadata and controls
254 lines (186 loc) · 8.25 KB
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
#pragma once
#include <string>
#include <vector>
#include <iostream>
#include "Player.h"
#include "Map.h"
#include "LoggingObserver.h"
using namespace std;
// Forward declarations -------------------------------------------------------------------------------------
class Card;
class Player;
class Territory;
// Orders Class ---------------------------------------------------------------------------------------------
/*
Base Order class representing a generic order in the game.
- validate() and execute() are virtual functions to be implemented by derived classes.
- clone() is a virtual function to create a copy of the order.
*/
class Order : public Subject, public ILoggable
{
public:
Order(); // Default constructor
Order(const std::string& name); // Parameterized constructor
Order(const Order& other); // Copy constructor
Order& operator=(const Order& other); // Assignment operator
virtual ~Order(); // Destructor
virtual bool validate() const = 0; // Verify if order is valid
virtual void execute() = 0; // Execute the order
virtual Order* clone() const = 0; // Virtual constructor
virtual std::string toString() const;
bool isExecuted() const; // Verify if order has been executed
friend std::ostream& operator<<(std::ostream& os, const Order& order); // Stream insertion operator
void setExecuted(bool executed); // Set executed status
std::string stringToLog() const override;
string getName() const;
protected:
void setEffect(const std::string& effect); // Set the effect description of the order
void setName(const std::string& name); // Set the name of the order
private:
std::string name;
bool executed;
std::string effect;
};
// DERIVED ORDER CLASSES ----------------------------------------------------------------------------------------
// Deploy Class -------------------------------------------------------------------------------------------------
class Deploy : public Order
{
public:
Deploy(); // Default constructor
Deploy(Player* issuer, Territory* target, int armies); // Parameterized constructor
Deploy(const Deploy& other); // Copy constructor
Deploy& operator=(const Deploy& other); // Assignment operator
~Deploy(); // Destructor
bool validate() const override;
void execute() override;
Order* clone() const override;
std::string toString() const override;
friend std::ostream& operator<<(std::ostream& os, const Deploy& order); // Stream insertion operator
private:
Player* issuer; // Player issuing the order
Territory* target; // Target territory
int armies; // Number of armies to deploy
};
// Advance Class ------------------------------------------------------------------------------------------------
class Advance : public Order
{
public:
Advance(); // Default constructor
Advance(Player* issuer, Territory* source, Territory* target, int armies);// Parameterized constructor
Advance(const Advance& other); // Copy constructor
Advance& operator=(const Advance& other); // Assignment operator
~Advance(); // Destructor
bool validate() const override;
void execute() override;
Order* clone() const override;
std::string toString() const override;
friend std::ostream& operator<<(std::ostream& os, const Advance& order); // Stream insertion operator
Territory* getSource() const;
Territory* getTarget() const;
private:
Player* issuer; // Player issuing the order
Territory* source; // Source territory
Territory* target; // Target territory
int armies; // Number of armies to move/attack with
};
// Bomb Class ---------------------------------------------------------------------------------------------------
class Bomb : public Order
{
public:
Bomb(); // Default constructor
Bomb(Player* issuer, Territory* target); // Parameterized constructor
Bomb(const Bomb& other); // Copy constructor
Bomb& operator=(const Bomb& other); // Assignment operator
~Bomb(); // Destructor
bool validate() const override;
void execute() override;
Order* clone() const override;
std::string toString() const override;
friend std::ostream& operator<<(std::ostream& os, const Bomb& order); // Stream insertion operator
private:
Player* issuer; // Player issuing the order
Territory* target; // Target territory
};
// Blockade Class -----------------------------------------------------------------------------------------------
class Blockade : public Order
{
public:
Blockade(); // Default constructor
Blockade(Player* issuer, Territory* target); // Parameterized constructor
Blockade(const Blockade& other); // Copy constructor
Blockade& operator=(const Blockade& other); // Assignment operator
~Blockade(); // Destructor
bool validate() const override;
void execute() override;
Order* clone() const override;
std::string toString() const override;
friend std::ostream& operator<<(std::ostream& os, const Blockade& order); // Stream insertion operator
private:
Player* issuer; // Player issuing the order
Territory* target; // Target territory
};
// Airlift Class ------------------------------------------------------------------------------------------------
class Airlift : public Order
{
public:
Airlift(); // Default constructor
Airlift(Player* issuer, Territory* source, Territory* target, int armies); // Parameterized constructor
Airlift(const Airlift& other); // Copy constructor
Airlift& operator=(const Airlift& other); // Assignment operator
~Airlift(); // Destructor
bool validate() const override;
void execute() override;
Order* clone() const override;
std::string toString() const override;
friend std::ostream& operator<<(std::ostream& os, const Airlift& order); // Stream insertion operator
private:
Player* issuer; // Player issuing the order
Territory* source; // Source territory
Territory* target; // Target territory
int armies; // Number of armies to airlift
};
// Negotiate Class -----------------------------------------------------------------------------------------------
class Negotiate : public Order
{
public:
Negotiate(); // Default constructor
Negotiate(Player* issuer, Player* targetPlayer); // Parameterized constructor
Negotiate(const Negotiate& other); // Copy constructor
Negotiate& operator=(const Negotiate& other); // Assignment operator
~Negotiate(); // Destructor
bool validate() const override;
void execute() override;
Order* clone() const override;
std::string toString() const override;
friend std::ostream& operator<<(std::ostream& os, const Negotiate& order); // Stream insertion operator
private:
Player* issuer; // Player issuing the order
Player* targetPlayer; // Target player to negotiate with
};
// OrdersList Class ---------------------------------------------------------------------------------------------
class OrdersList : public Subject, public ILoggable
{
public:
OrdersList(); // Default constructor
OrdersList(const OrdersList& other); // Copy constructor
OrdersList& operator=(const OrdersList& other); // Assignment operator
~OrdersList(); // Destructor
void add(const Order& order); // Add order to the list
void add(Order* order); // Add order pointer to the list
void remove(Order* order); // Remove order from the list (by pointer)
void remove(int index);// Deletes order from the list (by index)
void move(int fromIndex, int toIndex); // Move order within the list
int size() const; // Get number of orders in the list
const Order& at(int index) const; // Get order at specific index
Order& at(int index); // Get order at specific index (non-const)
bool operator==(const OrdersList& other) const;
friend std::ostream& operator<<(std::ostream& os, const OrdersList& ordersList); // Stream insertion operator
std::string stringToLog() const override;
std::vector<Order*>& getOrders() { return orders; }
const std::vector<Order*>& getOrders() const { return orders; }
private:
void clear(); // Clear all orders from the list
void deepCopy(const OrdersList& other); // Deep copy from another OrdersList
// Class members
std::vector<Order*> orders{}; // Vector of pointers to orders
};