forked from AA789-ai/WarzoneGame-COMP345
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMapDriver.cpp
More file actions
77 lines (54 loc) · 2.95 KB
/
MapDriver.cpp
File metadata and controls
77 lines (54 loc) · 2.95 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
#include "map.h"
#include <iostream>
#include "MapLoader.h"
//Function that tests loading of multiple map files.
//For each loaded map, it displays its properties, verifies its validity,
//and saves the valid maps in a vector.
void testLoadMaps(){
// List of map files to load
std::vector<std::string> mapsToLoad = {"./maps/3D.map", "./maps/3D invalid.map", "./maps/003_I72_Fairchild T-31.map", "./maps/003_I72_Fairchild T-31 invalid.map"};
std::vector<Map*> validMaps;
for (int i = 0; i < mapsToLoad.size(); i++){
MapLoader loader(mapsToLoad[i]);
Map* loadedMap = loader.loadMap();
// Check if the map was loaded successfully
if (!loadedMap) {
std::cerr << "Failed to load the map." << std::endl;
}
// Display some map properties for verification
std::cout << "Map Name: " << loadedMap->getName() << std::endl;
std::cout << "Map Author: " << loadedMap->getAuthor() << std::endl;
std::cout << "Map Image: " << loadedMap->getImage() << std::endl;
if (loadedMap->isValid()){
std::cout << "The map was valid" << std::endl;
validMaps.push_back(loadedMap);
} else {
std::cout << "The map was invalid" << std::endl;
delete loadedMap;
std::cout << "----------------------------------------------------------------------------------" << std::endl;
std::cout << "----------------------------------------------------------------------------------" << std::endl;
continue;
}
// Display continents and their properties
for (const Continent* continent : loadedMap->getContinents()) {
std::cout << "Continent Name: " << continent->getName() << std::endl;
std::cout << "Number of Bonus: " << continent->getBonus() << std::endl;
for (const Territory* territory : continent->getTerritories()) {
std::cout << " Territory: " << territory->getName() << " [" << territory->getX() << "," << territory->getY() << "], Number of armies: " << territory->getNumberOfArmies() << std::endl;
// Display adjacent territories for each territory
for (const Territory* adjacentTerritory : territory->getAdjacentTerritories()) {
std::cout << " Adjacent: " << adjacentTerritory->getName() << std::endl;
}
}
}
std::cout << "----------------------------------------------------------------------------------" << std::endl;
std::cout << "----------------------------------------------------------------------------------" << std::endl;
}
//Display the number of valid maps
std::cout << "Number of valid Maps are: " << validMaps.size() << std::endl;
//Free memory
for (Map* map : validMaps) {
delete map;
validMaps.clear();
}
}