forked from mbwilgus/comp345-winter2019
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMap.cpp
More file actions
83 lines (75 loc) · 1.95 KB
/
Copy pathMap.cpp
File metadata and controls
83 lines (75 loc) · 1.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
78
79
80
81
82
83
#include <string>
#include <iostream> //test
#include <vector>
#include <unordered_set>
using namespace std;
#include "Graph.h"
#include "City.h"
#include "Elektro.h"
#include "Map.h"
#include "MapLoader.h"
Map::Map(UndirectedGraph<City> cities)
{
powerGridMap = cities;
}
void Map::addElektroToBank(int amount)
{
bank.setElektro(bank.getElektro() + amount);
}
void Map::addResourceToPool(Resource r)
{
resourcePool.push_back(r);
}
void Map::addResourceToMarket(Resource r)
{
if(marketSize == 14) return;
resourceMarket[marketSize++] = r;
}
void Map::buyCity(City city, House house)
{
vector<Edge<City> > edges = powerGridMap.getEdges(city);
City current = powerGridMap.delVertex(city);
current.build(house);
powerGridMap.addVertex(current);
for(Edge<City> e: edges)
{
powerGridMap.addEdge(current, e.dest, e.cost);
}
}
unordered_set<City> Map::getCities() const
{
return powerGridMap.getVerts();
}
string Map::printMap() const
{
string mapText = "";
mapText += "--CITIES--\n";
unordered_set<City> cities = powerGridMap.getVerts();
for(City c : cities)
{
mapText += c.getName() + ":" + to_string(c.getRegion()) + ":" + c.getHouses() + "\n";
}
mapText += "--CITIES--\n\n";
mapText += "--CONNECTIONS--\n";
for(Edge<City> edge: powerGridMap.allEdges())
{
mapText += edge.source.getName() + ":" + edge.dest.getName() + ":" + to_string(static_cast<int>(edge.cost)) + "\n";
}
mapText += "--CONNECTIONS--\n\n";
mapText += "--MARKET--\n";
for(int i = 0; i < marketSize; i++)
{
mapText += getResourceName(resourceMarket[i]) + "\n";
}
mapText += "--MARKET--\n\n";
mapText += "--POOL--\n";
for(Resource r : resourcePool)
{
mapText += getResourceName(r) + "\n";
}
mapText += "--POOL--\n\n";
mapText += "--BANK--\n";
mapText += to_string(bank.getElektro()) + "\n";
mapText += "--BANK--";
return mapText;
}