DungeonMaker
main()-function
(how to use the interface)
This is a simplified version of the main() function (included in the
file download as simplemain.cpp), which shows how to use the
DungeonMaker interface to construct a dungeon:
#include "DungeonMaker.h"
#include (other libraries here)
int main( )
{
bool cY = true; //we want columns
bool gW = false; //we don't want generational walls
bool GSoutput = false; //we don't want output in Gridslammer format
char* roomsFile = "rooms5";
char* statsFile = "stats5";
srand( (unsigned) time( NULL ) ); //get a different dungeon each time
int x , y , maxCrawlers , srw , cds , jl , jd;
unsigned int mcw;
if(! ReadRoomsFile( roomsFile , x , y ) )
{//initialize dimensions of the dungeon
cout << "Cannot make dungeon\n";
return(0);
}
if(! ReadConstantsFile(maxCrawlers , mcw , srw , cds , jl , jd ) )
{//initialize other params used by DungeonMaker constructor from files
cout << "Cannot make dungeon\n";
return(0);
}
DungeonMaker* pDM = 0;
pDM = new DungeonMaker( x , y , cY , gW , maxCrawlers , mcw , srw , cds , jl , jd );
if(0 == pDM)
{
cout << "Cannot create DungeonMaker object, most likely because of insufficient memory.\n";
return(0);
}
if( !pDM -> InitializeStats(statsFile))
cout << "Input file " << statsFile << " is missing or corrupted, using default stats\n";
if( !pDM -> Initialize(roomsFile) )
{//failure, most likely missing file
cout << "The file " << roomsFile << " is missing or corrupted, exiting without creating dungeon.\n";
delete pDM;
return(0);
}
pDM -> MakeMap( ); //here the actual map gets created and all the work done
if(GSoutput) //you want GridSlammer output
pDM -> WriteMap( 100 );
else //you want .txt output
pDM -> WriteMap(1000);
///////////////////////////////////////////////////////////////////////////////////////////
//To use the map in your own program, replace the preceding 4 lines with the following
//int Xdimension = pDM->ShowDimX(); // or use the value x
//int Ydimension = pDM->ShowDimY(); // or use the value y
//YourMapClass* pYMC = new YourMapClas(Xdimension , Ydimension , ... );
//create your own map object of the proper dimension
//pYMC -> Initialize( pDM ); //initialize it to the values generated by DungeonMaker
//in your "Initialize" method, call pDM -> GetMap(i , j)
//for 0 <= i < x; 0 <= j < y
///////////////////////////////////////////////////////////////////////////////////////////
delete pDM;
if(GSoutput)
cout << "Printed Dungeon.grd, have a look. Hit any key to exit: ";
else
cout << "Printed Dungeon.txt, have a look. Hit any key to exit: ";
char input;
cin >> input; //necessary so that the console stays up long enough to read output in Windoze
return( 1 );
}
Yup! That's all it takes.