本文整理汇总了C++中Maze::getFloorCount方法的典型用法代码示例。如果您正苦于以下问题:C++ Maze::getFloorCount方法的具体用法?C++ Maze::getFloorCount怎么用?C++ Maze::getFloorCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Maze
的用法示例。
在下文中一共展示了Maze::getFloorCount方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: mazeFromXML
Maze* Maze::mazeFromXML(const std::string& filename) {
Maze* newMaze = nullptr;
try {
XMLDocument doc;
if (doc.LoadFile(filename.c_str()) == XML_SUCCESS) {
XMLElement* root = doc.RootElement();
if (!root || std::string(root->Name()).compare("maze") != 0) {
throw std::runtime_error("Maze::mazeFromXML(): Not a maze file.");
}
XMLElement* floorElement = root->FirstChildElement("floor");
if (!floorElement) {
throw std::runtime_error("Maze::mazeFromXML(): Empty maze.");
}
newMaze = new Maze();
while (floorElement && newMaze->getFloorCount() < Maze::MAX_FLOORS) {
if (!floorElement->GetText()) {
throw std::runtime_error("Maze::mazeFromXML(): Empty floor element.");
}
Map* floor = Map::mapFromXML(floorElement->GetText());
if (!floor) {
throw std::runtime_error("Maze::mazeFromXML(): Could not load a floor.");
}
newMaze->floors.push_back(floor);
floorElement = floorElement->NextSiblingElement("floor");
}
if (floorElement) {
// There was more than MAX_FLOORS floors. Best report it.
writeToLog(MessageLevel::WARNING, "Maze::mazeFromXML(): More than 256 floors specified for the maze. Stop this madness!");
}
newMaze->scanForEntrances();
}
}
catch (std::exception& e) {
if (newMaze) {
delete newMaze;
newMaze = nullptr;
}
writeToLog(MessageLevel::ERROR, "%s\n", e.what());
}
return newMaze;
}