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
|
// Read Textfile and place data into a map
int rnum=0, exitnum[10];
std:: string rname, shdesc,lgdesc="",dirarray[10]= {"n","ne","e","se","s","sw","w","nw","up","down"};
bool light, fight,lock, beenhere;
std::ifstream myfile;
myfile.open("Roomdata.dat");
if (myfile.is_open())
{
while (myfile.good())
{
myfile >> rnum; myfile.ignore(1,'\n');
getline(myfile,rname,'}'); myfile.ignore(1,'\n');
getline(myfile,shdesc,'}'); myfile.ignore(1,'\n');
getline(myfile,lgdesc,'}'); myfile.ignore(1,'\0');
myfile >> fight; myfile >> lock;
myfile >> light; myfile >> beenhere;
myfile.ignore(1,'\0');
for (int i=0; i<10; i++)
{
myfile >> exitnum[i];
}
Room *rname = new Room(rnum,shdesc,lgdesc,fight,lock,light,beenhere);
for (int i=0; i<10; i++){
rname->addExit(dirarray[i],exitnum[i]);
}
roomMap.addRoom(rname); // adds room to the map
}
myfile.close();
}
roomMap.changeRoom(1); // allows movement on the game map
// Read Item text file and place it into a class / vector of objects
std :: vector <Item> object;
std::string name, desc, tag= "";
int id, cost, loc = 0;
std::ifstream thefile;
thefile.open("Itemdata.dat");
if (thefile.is_open())
{
while (thefile.good())
{
getline(thefile,name,'}');
thefile.ignore(1,'\0');
getline(thefile,tag,'}');
thefile.ignore(1,'\0');
getline(thefile,desc,'}');
thefile.ignore(1,'\0');
thefile >> id >> cost >> loc;
thefile.ignore(1,'\0');
Item newobject (name, tag, desc, id, cost, loc);
object.push_back(newobject);
thefile.close();
}
}
|