#ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif #include "stdafx.h" #include "worldio.h" #include "object.h" #include "draggableobject.h" #include "crashingobject.h" #include #include // #include any other files containing your own personal object definitions // here. // Load a world from an istream. If a failure occurs while loading the world, // return false, else return true. bool loadWorld(istream& in, World* world) { int newX, newY; // The first two things in a world file are the dimensions of the world. if (! (in >> newX >> newY ) ) return false; world->setSize(newX, newY); char objName[30]; while (in >> setw(30) >> objName) { // Depending on what objName is, we create a new object. if (strcmp(objName, draggableObjectName)==0) { DraggableObject* newObj = new DraggableObject; in >> *newObj; world->addObject(newObj); } // You will want to add your own additional code here // that will check for and instantiate new objects that // you've created. if (strcmp(objName, crashingObjectName)==0) { CrashingObject* newObj = new CrashingObject; in >> *newObj; world->addObject(newObj); } } return true; } // Save a world to the ostream. If a failure occurs while saving the world, // return false, else return true. bool saveWorld(ostream& out, World* world) { // As always, the first thing to output in a world file is the // size of the world. long sizeX, sizeY; world->getSize(sizeX, sizeY); out << sizeX << " " << sizeY << endl << endl; // Next, output the items in the object list. ObjectList* objList = world->getAllObjects(); ObjectList::Position pos; for (objList->reset(pos); !objList->endOfList(pos); objList->advance(pos)) out << *(objList->data(pos)) << endl; if (out) return true; else return false; }