#include <fstream>
#include <ctime>
#include <random>
#include "Dungeon.h"
using namespace std;
int main()
{
srand(time(0));
//setting file stream
ofstream out;
out.open("dungeon.txt");
if(out.fail()){
perror("dungeon.txt");
return 1;
}
//generating and initializing dungeon
char **dungeon = new char*[D_HEIGHT];
for (int i = 0; i < D_HEIGHT; i++)
dungeon[i] = new char[D_WIDTH];
Dungeon dung;
dung.genDungeon(dungeon);
//print dungeon to the file
for (int y = 0; y<D_HEIGHT; y++){
for (int x = 0; x<D_WIDTH; x++){
out << dungeon[y][x];
}
out << "\n";
}
// De-Allocate memory to prevent memory leak and close the file
for (int i = 0; i < D_HEIGHT; ++i)
delete [] dungeon[i];
delete [] dungeon;
out.close();
return 0;
}
I2luY2x1ZGUgPGZzdHJlYW0+CiNpbmNsdWRlIDxjdGltZT4KI2luY2x1ZGUgPHJhbmRvbT4KCiNpbmNsdWRlICJEdW5nZW9uLmgiCgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKQp7CiAgICBzcmFuZCh0aW1lKDApKTsKICAgIC8vc2V0dGluZyBmaWxlIHN0cmVhbQogICAgb2ZzdHJlYW0gb3V0OwogICAgb3V0Lm9wZW4oImR1bmdlb24udHh0Iik7CiAgICBpZihvdXQuZmFpbCgpKXsKICAgICAgICBwZXJyb3IoImR1bmdlb24udHh0Iik7CiAgICAgICAgcmV0dXJuIDE7CiAgICB9CgogICAgLy9nZW5lcmF0aW5nIGFuZCBpbml0aWFsaXppbmcgZHVuZ2VvbgogICAgY2hhciAqKmR1bmdlb24gPSBuZXcgY2hhcipbRF9IRUlHSFRdOwogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBEX0hFSUdIVDsgaSsrKQogICAgICAgIGR1bmdlb25baV0gPSBuZXcgY2hhcltEX1dJRFRIXTsKICAgIER1bmdlb24gZHVuZzsKICAgIGR1bmcuZ2VuRHVuZ2VvbihkdW5nZW9uKTsKCiAgICAvL3ByaW50IGR1bmdlb24gdG8gdGhlIGZpbGUKICAg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