-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
168 lines (135 loc) · 5.07 KB
/
main.cpp
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
#include <iostream>
#include <ctime>
#include <cstdlib>
#include "mapGen.h"
#include "storm.h"
#include "encryption.h"
#include "PausePlay.h"
using namespace std;
int main(){
Control control;
while (true)
{
srand(static_cast<unsigned int>(time(nullptr)));
int timeLimit;
int refreshRate; //Variables for max # time steps & how often time steps are printed to the screen
int workers = 0;
int goods = 0; //Variables for # available workers & goods
int totalPollution = 0;
Zone myZone;
int xmax = 0;
int ymax = 0; //Variables for maximum value of x & y coordinates of city
list<Zone> mainList; //List of all zones
InitializeSim(mainList, timeLimit, refreshRate, xmax, ymax); //Initializes mainList, timeLimit, refreshRate, & zone coordinates
InitializeMap(mainList, xmax, ymax); //Initialize surrounding map
int changed=0; //# of changes in time step
//Output initial state
printOutput(mainList);
cout << "-- Initial State --" << endl;
cout << endl;
//Analyze every zone during each time step until time limit is reached
for(int i = 0; i < timeLimit; ++i){
changed=0;
//Analyze commercial, then industrial, then residential zones
for(auto& it : mainList){
it.CheckAdjZonesC(workers, goods, changed, mainList);
}
for(auto& it : mainList){
it.CheckAdjZonesI(workers, goods, changed, mainList);
}
for(auto& it : mainList){
it.CheckAdjZonesR(workers, goods, changed, mainList);
}
//Reset all zones to unchanged
for(auto& it : mainList){
it.SetPrevChanged(false);
}
//if there is no change inbetween it stops the loop
if(changed == 0){
cout << endl;
cout << "~~ No change between time steps. ~~" << endl;
cout << endl;
break;
}
//Print output for current time step if appropriate for specified refresh rate
if(i%refreshRate == 0){
printOutput(mainList);
}
//Calculate total # available workers & goods
workers = myZone.CalcWorkers(mainList, workers);
cout<<"Time Step: "<<i+1<<endl;
cout<<"Available Workers: "<<workers<<endl;
cout<<"Available Goods: "<<goods<<endl;
cout<<endl;
// Spread pollution
for(auto& it : mainList){
it.spreadPollution(mainList);
}
//storm simulation
bool severesimu= false;
severesimu= storm(mainList);
if(severesimu){
cout<<"Severe Weather"<<endl;
severe(mainList);
if(workers>0){
workers=workers/2;
}
if(goods>0){
goods=goods/2;
}
}
cout<<endl;
char build; //Whether or not user wants to build a new zone
int totalPop = 0; //Total population of city
int builtZones = 0; //# Additional zones built
//Calculate total city population
for(auto it : mainList){totalPop = totalPop + it.GetPop();}
//Pause and Play
Control::Command command = control.getUserCommand();
if (command == Control::Command::Quit) {
std::cout << "Program terminating...\n";
break;
}
if (command == Control::Command::Pause) {
std::cout << "Program paused...\n";
control.waitForPlay();
std::cout << "Program resumed...\n";
}
cout << "Would you like to build a new city zone? Enter Y/N: ";
cin >> build;
cin.ignore();
if(build == 'Y'){BuildMenu(totalPop, builtZones, mainList);}
}
// Update totalPollution
totalPollution = 0;
for (auto& it : mainList) {
totalPollution += it.getPollutionLevel();
}
//final print
cout << endl;
cout << "-- Final State --" << endl;
cout << endl;
printOutput(mainList);
//print final population of each zone
printPop(mainList);
//print area wanted by student and get coordinates
printArea(mainList);
//print pollution
printPollution(mainList);
cout<< "Total Pollution: "<<totalPollution<<endl;
char userinp;
vector<int> encryptVals;
cout << "Do you want to encrypt? Y/N" << endl;
cin >> userinp;
if((userinp == 'Y') || (userinp == 'y')){
publicKey(encryptVals);
encryptSim(mainList, encryptVals);
//final print
printOutput(mainList);
//print final population of each zone
printPop(mainList);
privateKey(mainList, encryptVals);
}
return 0;
}
}