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
|
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <vector>
using namespace std;
//This program teraforms a map based on input from a "History of Disasters" file which is the history of what has happened to land through time given a begining map and provides the end map and all maps in between all disasters.
void plot_map(const vector<vector<char> > &someMap, ostream & outstream); //Outputs the map
void HorizontalQuake(int row, int col, vector<vector<char> > & map); //replaces an entire row with '-'
void VerticalQuake(int row, int col, vector<vector<char> > & map); //replaces an entire column with '|'
void HorizontalChasm(int row, int col, vector<vector<char> > & map); //erases an entire row
void VerticalChasm(int row, int col, vector<vector<char> > & map); //erases an entire column
void Meteor(int row, int col, int reach, vector<vector<char> > & map, int rowC, int colC, vector<vector<vector<char> > > & mapset); //replaces an area affected by meteor by Ms
vector<vector<vector<char> > > mapset;
void plot_map(const vector<vector<char> > &someMap, ostream & outstream)
{
int a = mapset.size();
for(a; a > 0; a--)
{
int b = mapset[a].size(); //number of rows for outputted map
for(int c = 0; b > c; c++)
{
int d = mapset[a][c].size();
for(int e = 0; d > e; e++)
{
outstream << mapset[a][c][e];
}
}
outstream << endl;
}
return;
}
void HorizontalQuake (int row, int col, vector<vector<char> > & map)
{
int colI = col;
for(colI; colI > 0; colI--)
{
map[row][colI] = '-';
}
return;
}
void HorizontalChasm (int row, int col, vector<vector<char> > & map)
{
map.erase(map.begin()+row+1);
return;
}
void VerticalQuake(int row, int col, vector<vector<char> > & map)
{
int rowI = row;
for(rowI; rowI > 0; rowI--)
{
map[row][col] = '|';
}
return;
}
void VerticalChasm(int row, int col, vector<vector<char> > & map)
{
int rowI;
rowI = row;
for(rowI; rowI > 0; rowI--)
{
map[rowI].erase(map[rowI].begin() + col);
}
return;
}
void Meteor(int row, int col, int reach, vector<vector<char> > & map, int rowC, int colC, vector<vector<vector<char> > > & mapset)
{
int rowI = rowC;
int colI = colC;
if(row < 1 or col < 1 or row > rowC or col > colC)
{
return;
}
else
{
for(rowI; rowI > 0; rowI--)
{
for(colI; colI > 0; colI--)
{
if((rowC-reach) < rowI and (rowC+reach) > rowI and (colC-reach) < colI and (colC+reach) > colI)
{
map[rowI][colI] = 'M';
mapset.push_back(map);
}
}
}
}
return;
}
int main()
{
int rowO, colO, rowC, colC, rowI, colI; //row and column orginial, current, and index
string dis; //string of disaster
ifstream mapfile; //the map which is given
ifstream hond; //history_of_natural_disasters
mapfile.open("map.txt");
hond.open("history_of_natural_disasters.txt");
mapfile >> rowO >> colO;
vector<char> rows(rowO);
vector<vector<char> > map(colO, rows);
rowC = rowO;
colC = colO;
rowI = rowO;
colI = colO;
//following for loop records the current map
char temp;
for(rowI; rowI > 0; rowI--)
{
for(colI; colI > 0; colI--)
{
mapfile >> temp;
map[(rowC - rowI)][(colC-colI)] = temp;
}
}
hond >> dis;
int location, loc1, loc2, reach;
mapset.push_back(map);
while(!hond.eof())
{
if(dis == "HorizontalQuake")
{
hond >> location;
if(location <= rowC and location > 0)
{
HorizontalQuake(location, colC, map);
mapset.push_back(map);
}
}
else if(dis == "HorizontalChasm")
{
hond >> location;
if(location <= rowC and location > 0)
{
HorizontalChasm(location, colC, map);
mapset.push_back(map);
rowC--;
}
}
else if(dis == "VerticalQuake")
{
hond >> location;
if(location <= colC and location > 0)
{
VerticalQuake(rowC, location, map);
mapset.push_back(map);
}
}
else if(dis == "VerticalChasm")
{
hond >> location;
if(location <= rowC and location > 0)
{
VerticalChasm(rowC, location, map);
mapset.push_back(map);
colC--;
}
}
else if(dis == "Meteor")
{
hond >> loc1 >> loc2 >> reach;
Meteor(loc1, loc2, reach, map, rowC, colC, mapset);
//loc1 = row number, loc2 = column number
//further note to self, the boundry check is done within the function
}
else
{
cout << "The code failed, and I am frustrated! Screw you Engr101" << endl;
return 0;
}
hond >> dis;
}
ofstream map_history;
map_history.open("map_history.txt");
plot_map(map, map_history);
map_history.close();
return 0;
}
|