-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMap.h
More file actions
125 lines (98 loc) · 3.03 KB
/
Map.h
File metadata and controls
125 lines (98 loc) · 3.03 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
#ifndef MAP_H
#define MAP_H
#include <iostream>
#include <vector>
#include <string>
#include <memory>
class Player; // Forward declaration
// Territory class
class Territory {
public:
Territory(const std::string& name, int x, int y, const std::string& continent);
// Rule of Three
Territory(const Territory& other);
Territory& operator=(const Territory& other);
~Territory();
//Comparison Operator Overloading
bool operator == (const Territory& territory);
bool operator != (const Territory& territory);
// Getters
std::string getName() const;
std::string getContinent() const;
Player* getOwner() const;
int getArmies() const;
// Setters
void setOwner(Player* owner);
void setArmies(int armies);
// Adjacency management
void addAdjacentTerritory(Territory* territory);
const std::vector<Territory*>& getAdjacentTerritories() const;
// Stream insertion
friend std::ostream& operator<<(std::ostream& os, const Territory& territory);
// Verify Adjacency
bool isAdjacentTo(const Territory* other) const;
private:
std::string* name;
int x;
int y;
std::string* continent;
Player* owner;
int armies;
std::vector<Territory*> adjacentTerritories;
};
// Continent class
class Continent {
public:
Continent(const std::string& name, int bonus);
// Rule of Three
Continent(const Continent& other);
Continent& operator=(const Continent& other);
~Continent();
// Getters
std::string getName() const;
int getBonus() const;
// Territory management
void addTerritory(Territory* territory);
const std::vector<Territory*>& getTerritories() const;
// Stream insertion
friend std::ostream& operator<<(std::ostream& os, const Continent& continent);
private:
std::string* name;
int bonus;
std::vector<Territory*> territories;
};
// Map class
class Map {
public:
Map();
// Rule of Three
Map(const Map& other);
Map& operator=(const Map& other);
~Map();
// Territory and Continent management
void addTerritory(Territory* territory);
void addContinent(Continent* continent);
// Getters
const std::vector<Territory*>& getTerritories() const;
const std::vector<Continent*>& getContinents() const;
Territory* getTerritoryByName(const std::string& name) const;
// Validation methods
bool validate();
bool isConnectedGraph();
bool continentsAreConnectedSubgraphs();
bool eachCountryInOneContinent();
// Stream insertion
friend std::ostream& operator<<(std::ostream& os, const Map& map);
private:
std::vector<Territory*> territories;
std::vector<Continent*> continents;
// Helper methods for graph traversal
void dfs(Territory* territory, std::vector<bool>& visited);
void dfsContinent(Continent* continent, Territory* territory, std::vector<bool>& visited);
};
// MapLoader class
class MapLoader {
public:
static Map* loadMap(const std::string& filename);
};
#endif